[PySide] QMediaPlayer cannot play mp3 audio files

Alexey Vihorev vihorev at gmail.com
Mon Nov 7 12:09:56 CET 2022


BTW this piece of code works fine on PyQt6.

------ Исходное сообщение ------
От "Zhao Lee" <redstone-cold at 163.com>
Кому "pyside" <pyside at qt-project.org>
Дата 07.11.2022 11:57:42
Тема Re: [PySide] QMediaPlayer cannot play mp3 audio files

>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())
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20221107/a053f2d2/attachment.htm>


More information about the PySide mailing list