调试了一上午,然后各种查询,错误还算是解决了。 错误代码:
代码语言:javascript复制 def PlayMp3(self):
self.player = QMediaPlayer()
self.player.setMedia(QMediaContent(QUrl.fromLocalFile("D:Python 1.mp3")))
#self.player.setVolume(25)
self.player.play()
错误提示:
代码语言:javascript复制DirectShowPlayerService::doSetUrlSource: Unresolved error code 0x8007007b (??????????????????????????)
错误一般代表:路径错误或者底层库错误,底层库为:LAV filter,需要安装。 解决方案:
代码语言:javascript复制 def PlayMp3(self):
self.player = QMediaPlayer()
self.player.setMedia(QMediaContent(QUrl.fromLocalFile("D:\Python\01.mp3")))
#self.player.setVolume(25)
self.player.play()
代码语言:javascript复制 def PlayMp3(self):
self.player = QMediaPlayer()
self.player.setMedia(QMediaContent(QUrl.fromLocalFile("D:/Python/01.mp3")))
#self.player.setVolume(25)
self.player.play()
各种搜索问题,很奇怪。 在Qt(C )官方例子中,代码样例如下:
代码语言:javascript复制player = new QMediaPlayer;
connect(player, SIGNAL(positionChanged(qint64)), this, SLOT(positionChanged(qint64)));
player->setMedia(QUrl::fromLocalFile("/Users/me/Music/coolsong.mp3"));
player->setVolume(50);
player->play();
我通过读取文件,打印路径时,打印如下;
代码语言:javascript复制D:Pythonui.py
之前读取本地图片是写过如下代码,测试:
代码语言:javascript复制self.m_photo = PhotoImage(file = "D:Python\66logo.png")
self.m_label = Label(self,text = "Python学习",font = ('Arial', 15),bg= "blue",fg = "red",width = 240,height = 200,compound = CENTER)
然后再次 测试,代码如下:
代码语言:javascript复制 def PlayMp3(self):
self.player = QMediaPlayer()
self.player.setMedia(QMediaContent(QUrl.fromLocalFile("D:Python\01.mp3")))
#self.player.setVolume(25)
self.player.play()
问题原因:在 Python中,’ ’,或者’x’……等等一系列表示特殊字符,需要所以需要转义‘x’,以后注意。