pyqt播放音频

发布时间 2023-03-31 06:13:00作者: 西北逍遥

pyqt播放音频

 

 

from PyQt5.QtCore import QUrl
from PyQt5.QtMultimedia import QMediaPlayer
from PyQt5.QtWidgets import QApplication

import sys

app = QApplication(sys.argv)

# Create a QMediaPlayer object
player = QMediaPlayer()

# Set the media to play
url = QUrl.fromLocalFile("path/to/file.mp3")
player.setMedia(url)

# Play the media
player.play()

# Exit the application when the media has finished playing
player.stateChanged.connect(lambda state: app.quit())

# Run the application
sys.exit(app.exec_())

 

 

 

#######################