简体   繁体   中英

Can't play .mp3 file using winsound on windows

I am trying to play an audio file but it only makes the windows alert sound when I open/run the code. How do I fix this?

EDIT: nothing on winsound works it just makes the windows alert noise (windows background.wav) right click on the sound button (bottom right), click sounds, click on the first one and press test. that's the noise.


code:

import winsound
winsound.PlaySound('music.mp3', winsound.SND_ASYNC)

The winsound.PlaySound() function is just a thin wrapper around the PlaySound() Win32 API , which only plays waveform audios (WAV) and cannot recognize MP3 files.

If you're not willing to convert the file to WAV manually, you may use theMCI components .

The third-party playsound library provides a concise example for its usage, you can either install it or learn from its source code.

by using pygame I found:

from pygame import mixer # Load the required library

mixer.init()
mixer.music.load('music.mp3')
mixer.music.play()

which works fine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM