Skip to content

Commit 54bed26

Browse files
Merge pull request #2538 from SyedImtiyaz-1/ConsolePlayer
Added Console Music Player
2 parents 91edc02 + 87dbe55 commit 54bed26

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

MusicPlayer-Py/Play.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import os
2+
from os import walk
3+
import os.path
4+
import sys
5+
import pygame
6+
from pygame import mixer
7+
8+
9+
#init mixer process
10+
mixer.init()
11+
12+
#get files
13+
songs = []
14+
15+
os.chdir(os.getcwd() + '/songs')
16+
17+
for (dirpath, dirnames, filenames) in walk(os.getcwd()):
18+
songs.extend(filenames)
19+
break
20+
21+
22+
23+
24+
it = 0
25+
26+
#player
27+
while True:
28+
song = songs[it]
29+
30+
mixer.music.load(song) #load song
31+
mixer.music.set_volume(0.5) #set volume
32+
mixer.music.play() #play
33+
34+
playing = 1
35+
36+
while True:
37+
os.system('cls')
38+
39+
print("-----------------------------------------")
40+
print("---------- ZABE MUSIC PLAYER ----------")
41+
print("------------------------------------------")
42+
print(" Current song: " + song + "")
43+
print(" A(<<) (>>)D")
44+
print(" Volume: " + str(int(100*mixer.music.get_volume())) + "%· W(++) (--)S")
45+
print(" P: play/pause")
46+
print(" E: exit")
47+
print("-----------------------------------------")
48+
print(" Current song: " + song)
49+
print(" Songs queued: " + str(len(songs)))
50+
51+
action = input(">>> ")
52+
53+
if action == 'P' or action == 'p': #play,pause
54+
if playing:
55+
mixer.music.pause()
56+
playing = 0
57+
else:
58+
mixer.music.unpause()
59+
playing = 1
60+
elif action == 'W' or action == 'w': #volume up
61+
v = mixer.music.get_volume()
62+
mixer.music.set_volume(v + 0.1)
63+
elif action == 'S' or action == 's': #volume down
64+
v = mixer.music.get_volume()
65+
mixer.music.set_volume(v- 0.1)
66+
elif action == 'A' or action == 'a': #previous song
67+
it = (it - 1)%len(songs)
68+
break
69+
elif action == 'D' or action == 'd': #next song
70+
it = (it + 1)%len(songs)
71+
break
72+
elif action == 'E' or action == 'e': #stop
73+
mixer.music.stop()
74+
print("Closing...")
75+
sys.exit(0)

MusicPlayer-Py/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# **Console Music Player**
2+
3+
## All right reserved by py3
4+
Music player for console written in Python.
5+
6+
## Instructions
7+
8+
- Don't forget to put the song in the songs folder because the .py code fetching the data and then playing the song.

MusicPlayer-Py/songs/music.mp3

4.87 MB
Binary file not shown.

0 commit comments

Comments
 (0)