Install Pygame (This is the python3,32 bit)
PIP installs this WHL file
Just run the code when you're done, it's short.
import timeimport pygamefile=r‘C:\Users\chan\Desktop\Adele - All I Ask.mp3‘pygame.mixer.init()print("播放音乐1")track = pygame.mixer.music.load(file)pygame.mixer.music.play()time.sleep(10)pygame.mixer.music.stop()
Function: Play music after 10 seconds stop appendix
Pygame.init () initializes all modules,
Pygame.mixer.init () or just initialize the audio section
Pygame.mixer.music.load (' Xx.mp3 ') uses filename as a parameter to load music, music can be in Ogg, MP3 and other formats. The loaded music does not all go into the content, but is played as a stream, that is, when it is played, it is read from the file a little bit.
Pygame.mixer.music.play () plays the loaded music. The function returns immediately and the music is played in the background.
The play method can also use two parameters
Pygame.mixer.music.play (loops=0, start=0.0) loops and start respectively represent the number of repetitions and where the playback begins.
Pygame.mixer.music.stop () stops playing,
Pygame.mixer.music.pause () pauses playback.
Pygame.mixer.music.unpause () cancels the pause.
Pygame.mixer.music.fadeout (time) is used to fade out, and the volume is gradient from the initial value to 0 in times of milliseconds and finally stops playing.
Pygame.mixer.music.set_volume (value) to set the volume of playback, the volume value can range from 0.0 to 1.0.
Pygame.mixer.music.get_busy () to determine if the music is playing, return 1 is playing.
Pygame.mixer.music.set_endevent (Pygame. Userevent + 1) When the music playback is complete, notify the user program by event, and set the Pygame to be sent when the music playback is complete. Userevent+1 event to the user program. Pygame.mixer.music.queue (filename) uses the specified next music file to play, and the current music playback automatically starts playing the specified next. Only one music file waiting to be played can be specified at a time.
Python plays MP3 with the Pygame module