gpt4 book ai didi

PySide.phonon 和媒体格式,如 mp4、flv、mkv、eg

转载 作者:行者123 更新时间:2023-12-02 06:00:43 25 4
gpt4 key购买 nike

我绝对是一个pyside新手,想用PySide.phonon写一个媒体播放器。我的问题是:媒体播放器可以支持mp4,flv,mkv,eg等媒体格式吗?

最佳答案

回答这个问题的最佳方法是尝试播放您感兴趣的文件类型,或者检查支持的 mimetypes 列表。

这是一个演示视频播放器,您应该可以做到这一点:

from PySide import QtGui, QtCore
from PySide.phonon import Phonon

class Window(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.setWindowTitle('Video Player')
self.media = Phonon.MediaObject(self)
self.video = Phonon.VideoWidget(self)
self.video.setMinimumSize(400, 400)
self.audio = Phonon.AudioOutput(Phonon.VideoCategory, self)
Phonon.createPath(self.media, self.audio)
Phonon.createPath(self.media, self.video)
self.buttonChoose = QtGui.QPushButton('Choose File', self)
self.buttonMimes = QtGui.QPushButton('Show Mimetypes', self)
self.slider = Phonon.VolumeSlider(self)
self.slider.setAudioOutput(self.audio)
layout = QtGui.QGridLayout(self)
layout.addWidget(self.video, 0, 0, 1, 2)
layout.addWidget(self.buttonChoose, 1, 0)
layout.addWidget(self.buttonMimes, 1, 1)
layout.addWidget(self.slider, 2, 0, 1, 2)
layout.setRowStretch(0, 1)
self.media.stateChanged.connect(self.handleStateChanged)
self.buttonChoose.clicked.connect(self.handleButtonChoose)
self.buttonMimes.clicked.connect(self.handleButtonMimes)

def handleButtonChoose(self):
if self.media.state() == Phonon.PlayingState:
self.media.stop()
else:
dialog = QtGui.QFileDialog(self)
dialog.setFileMode(QtGui.QFileDialog.ExistingFile)
if dialog.exec_() == QtGui.QDialog.Accepted:
path = dialog.selectedFiles()[0]
self.media.setCurrentSource(Phonon.MediaSource(path))
self.media.play()
dialog.deleteLater()

def handleButtonMimes(self):
dialog = MimeDialog(self)
dialog.exec_()

def handleStateChanged(self, newstate, oldstate):
if newstate == Phonon.PlayingState:
self.buttonChoose.setText('Stop')
elif (newstate != Phonon.LoadingState and
newstate != Phonon.BufferingState):
self.buttonChoose.setText('Choose File')
if newstate == Phonon.ErrorState:
source = self.media.currentSource().fileName()
print ('ERROR: could not play: %s' % source)
print (' %s' % self.media.errorString())

class MimeDialog(QtGui.QDialog):
def __init__(self, parent):
QtGui.QDialog.__init__(self, parent)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.setWindowTitle('Mimetypes')
listbox = QtGui.QListWidget(self)
listbox.setSortingEnabled(True)
backend = Phonon.BackendCapabilities
listbox.addItems(backend.availableMimeTypes())
layout = QtGui.QVBoxLayout(self)
layout.addWidget(listbox)
self.resize(300, 500)

if __name__ == '__main__':

import sys
app = QtGui.QApplication(sys.argv)
app.setApplicationName('Phonon Player')
window = Window()
window.show()
sys.exit(app.exec_())

关于PySide.phonon 和媒体格式,如 mp4、flv、mkv、eg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12192684/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com