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 )
0 commit comments