2

I'm definitely in need of your help guys.. As in really. My laptop has been stolen and I didn't have a backup of my pyqt phonon video player that I made a year ago. I forgot how and what to do to recreate it.
I only know some key things to do for it to work. So please help me out.

From what i can remember I need to

  • Set backend capabilities (set phonon backend to windows media player?)
  • Install the required codecs (which i dont have a copy of)
  • Code the program (and sadly I forgot how to play a video)

If there's someone out there who have a working sample python videoplayer, can you please share it with me?

I'm trying it right now and my sample doesn't work at all

from PyQt4.phonon import Phonon
        media_source = phonon.Phonon.MediaSource("C:\\Sample.avi")
        self.ui.videoPlayer.load(media_source)
        self.ui.videoPlayer.play()

Please help me. And thank you very much to you guys.

I'm using python 2.6 and qt version 4.9. Now I'm coding on a virtual box windows XP

EDIT: got a following sample with this problem but.. having this error when loading a file.

"The Operation Cannot Be Performed Because the Pins Are Not Connected"

This maybe because I'm using a virtual box in Ubuntu?

4

1 回答 1

7

不要忘记show()视频播放器。其余的,根据我的经验,Phonon 经常很难找到在 Windows 上播放视频所需的编解码器。安装 K-Lite 编解码器包可能适用于这种情况。

这是一个对我有用的独立示例(Windows Vista32、Python 2.6.5、PyQt 4.7.3)。

import sys
from PyQt4 import QtCore, QtGui
from PyQt4.phonon import Phonon
app = QtGui.QApplication(sys.argv)
vp = Phonon.VideoPlayer()
media = Phonon.MediaSource('C:\\video.mp4')
vp.load(media)
vp.play()
vp.show()
sys.exit(app.exec_())

编辑:

多人最近评论说上述代码不再提供所需的行为。我已经很久没有使用 PyQt 了,但我怀疑其中一个更新可能已经改变了 Phonon 的功能。

根据评论者的说法,vp.show()现在需要在之前调用Phonon.MediaSource(),即:

...
vp = Phonon.VideoPlayer()
vp.show()
media = Phonon.MediaSource('C:\\video.mp4')
vp.load(media)
vp.play()
sys.exit(app.exec_())
于 2012-10-02T09:53:30.640 回答