我尝试使用libvlc在python 3中制作一个播放器,以使播放器具有播放列表,音轨和音频输出通道选项,但是我在使用文档时遇到了麻烦。我希望有人可以帮助我:
谢谢
from PyQt5 import QtCore, QtGui, QtWidgets
import keyboard
import vlc
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.setWindowFlags(QtCore.Qt.FramelessWindowHint)
Form.setWindowModality(QtCore.Qt.NonModal)
Form.setEnabled(True)
Form.resize(1024, 720)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(Form.sizePolicy().hasHeightForWidth())
Form.setSizePolicy(sizePolicy)
Form.setMinimumSize(QtCore.QSize(1024, 720))
Form.setMaximumSize(QtCore.QSize(1024, 720))
Form.setAutoFillBackground(False)
self.frame = QtWidgets.QFrame(Form)
self.frame.setGeometry(QtCore.QRect(0, 0, 1024, 720))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.frame.sizePolicy().hasHeightForWidth())
self.frame.setSizePolicy(sizePolicy)
self.frame.setMinimumSize(QtCore.QSize(1024, 720))
self.frame.setStyleSheet("QFrame{\n"
"background-color: rgb(38, 38, 38);\n"
" }")
self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame.setObjectName("frame")
self.instance = vlc.Instance()
self.au = vlc.AudioOutputChannel()
self.media = None
self.mediaplayer = self.instance.media_player_new()
playlist = (r"C:\Users\masdika\Downloads\videoplayback (3).mp4", r"C:\Users\masdika\Downloads\600548.mp4")
self.media = self.instance.media_new(playlist[0])
self.mediaplayer.set_media(self.media)
self.mediaplayer.set_hwnd(int(self.frame.winId()))
self.mediaplayer.play()
keyboard.add_hotkey("space",self.butt)
keyboard.add_hotkey("l",self.audioleft)
keyboard.add_hotkey("r",self.audioright)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
#self.audio()
def butt(self):
if self.mediaplayer.is_playing():
print("pause")
self.mediaplayer.pause()
else:
print("play")
self.mediaplayer.play()
def audioleft(self):
print("L")
self.au.AudioOutputChannel.Left()
def audioright(self):
print("R")
self.au.AudioOutputChannel.Right()
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Form = QtWidgets.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())
我阅读了有关更改音频输出通道的文档,但使用的是AudioOutputChannel类,但我无法尝试这样做并导致错误。