[PySide] QMediaPlayer cannot play mp3 audio files

Zhao Lee redstone-cold at 163.com
Mon Nov 7 10:57:42 CET 2022


After reviewing the doc of https://doc.qt.io/qt-6/qmediaplayer.html
I found I adopted an outdated way of using QMediaPlayer, after porting to the standard way advocating by the doc, I got Error.FormatError, so maybe I should back to Qt5(it is working) and wait for Qt 6.5 to solve the problem. 
from PySide6.QtCore import*
from PySide6.QtGui import*
from PySide6.QtWidgets import*
from PySide6.QtMultimedia import*


import sys



classMainWindow(QMainWindow):  #


    def__init__(self, parent=None):
        super().__init__(parent)



        self.player =QMediaPlayer()


        self.player.errorOccurred.connect(lambdaerr:print(err))
        self.audioOutput =QAudioOutput()
        self.player.setAudioOutput(self.audioOutput)
        self.player.setSource(QUrl('http://dict.youdao.com/dictvoice?audio={}&type=2'.format('good')))
        # self.player.setSource(QUrl("https://files.51voa.cn/202211/millions-of-americans-will-not-vote-in-english-on-election-day.mp3"))
        self.audioOutput.setVolume(50)
        self.player.play()



if __name__ =="__main__":


    app =QApplication(sys.argv)
    MainWindow =MainWindow()
    MainWindow.show()
    sys.exit(app.exec())













At 2022-11-07 17:21:14, "Zhao Lee" <redstone-cold at 163.com> wrote:

QMediaPlayer cannot play mp3 audio files, no sound,。
Tested with the latest PySide on win11


from PySide6.QtCore import*
from PySide6.QtGui import*
from PySide6.QtWidgets import*
from PySide6.QtMultimedia import*


import sys



classMainWindow(QMainWindow):  #


    def__init__(self, parent=None):
        super().__init__(parent)


        player =QMediaPlayer()
        # player.setSource(QUrl('http://dict.youdao.com/dictvoice?audio={}&type=2'.format('good')))
        player.setSource(QUrl('https://files.51voa.cn/202211/millions-of-americans-will-not-vote-in-english-on-election-day.mp3'))
       
        player.play()



if __name__ =="__main__":


    app =QApplication(sys.argv)
    MainWindow =MainWindow()
    MainWindow.show()
    sys.exit(app.exec())

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20221107/d93e42dc/attachment-0001.htm>


More information about the PySide mailing list