资源简介

PyQt5:利用QMediaPlayer,QVideo实现简单视频播放器。列表。进度条,播放、暂停。

资源截图

代码片段和文件信息

import os
import time
import sys

FileName = os.path.basename(sys.argv[0])
FilePath = sys.argv[0].replace(FileName““)
UiName = FileName.replace(“.py““.ui“)
UiPath = FilePath +UiName
Ui_pyName = FilePath+“ui.py“
FileFlag = os.path.isfile(Ui_pyName)

if FileFlag == 0:
sys_cmd  = os.popen(“pyuic5“+“ -o “+Ui_pyName+“ “+UiPath)
time.sleep(1)

from ui import Ui_Form
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtMultimedia import *
from PyQt5.QtMultimediaWidgets import *

class m_window(QWidgetUi_Form):
Index_Signle = pyqtSignal(int)
def __init__(self):
super(m_windowself).__init__()
self.setupUi(self)
self.PushButtonInit()
self.ProgressBarInit()
self.mplayer = QMediaPlayer(self)
self.ListWidgetInit()
self.mplayList.setCurrentIndex(0)
self.mVideoWin = QVideoWidget(self)
self.mVideoWin.setGeometry(55640480)
self.mplayer.setVideoOutput(self.mVideoWin)
self.play.clicked.connect(self.PlayVideo)
self.stop.clicked.connect(self.StopVideo)
self.mplayer.positionchanged.connect(self.PlaySlide)
self.mplayer.durationchanged.connect(self.MediaTime)
self.listWidget.itemDoubleClicked.connect(self.GetItem)
self.Index_Signle.connect(self.SetPlayMedia)

def PushButtonInit(self):
self.play = QPushButton(self)
self.play.setGeometry(54955020)
self.play.setText(“Play“)
self.play.show()
self.stop = QPushButton(self)
self.stop.setGeometry(654955020)
self.stop.setText(“stop“)
self.stop.show()

def ProgressBarInit(self):
self.Slider = QSlider(Qt.Horizontalself)
self.Slider.setGeometry(15049520020)
self.Slider.setRange(0100)
self.Slider.show()

def PlayVideo(self):
self.mplayer.play()

def StopVideo(self):
self.mplayer.pause()

def MediaTime(selftime):
self.Slider.setValue(0)
self.time = self.mplayer.duration() /1000
self.Slider.setRange(0int(self.time))
# self.scal = self.time / 100

def PlaySlide(selfval):
# self.Slider.setValue(int(val/1000/self.scal))
self.Slider.setValue(int(val/1000))

def ListWidgetInit(self):
self.mplayList = QMediaPlaylist();
self.mplayList.addMedia(QMediaContent(QUrl.fromLocalFile(“https://vd1.bdstatic.com/mda-hg6uempmez9u6mqi/sc/mda-hg6uempmez9u6mqi.mp4?auth_key=1562172911-0-0-4c22196ad1d0fcc49402d91336c999c5&bcevod_channel=searchbox_feed&pd=bjh&abtest=all“)))
self.mplayList.addMedia(QMediaContent(QUrl.fromLocalFile(“https://vd1.bdstatic.com/mda-hgdizw7w7fpc1pcr/sc/mda-hgdizw7w7fpc1pcr.mp4?auth_key=1562254279-0-0-703eb2eca1f7017eaa49b62a7ef56dda&bcevod_channel=searchbox_feed&pd=bjh&abtest=all“)))
self.mplayer.setPlaylist(self.mplayList)
self.mplayList.setPlaybackMode(QMediaPlaylist.CurrentItemInLoop)
self.listWidget.addItem(“1“)
self.listWidget.addItem(“2“)

def SetPlayMedia(selfIndex):
self.mplayer.stop()
self.mplayList.setCurrentIndex(Index)
self.mplayer.play()

def GetItem(selfItem):

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-07-02 23:01  pyVideo\.vs\
     目录           0  2019-07-02 23:01  pyVideo\.vs\pyVideo\
     目录           0  2019-07-02 23:01  pyVideo\.vs\pyVideo\v15\
     文件       28672  2019-07-05 22:19  pyVideo\.vs\pyVideo\v15\.suo
     文件         956  2019-07-02 23:01  pyVideo\pyVideo.sln
     目录           0  2019-07-05 22:04  pyVideo\pyVideo\
     目录           0  2019-07-04 22:50  pyVideo\pyVideo\__pycache__\
     文件         979  2019-07-04 22:50  pyVideo\pyVideo\__pycache__\ui.cpython-36.pyc
     文件        3170  2019-07-05 22:04  pyVideo\pyVideo\pyVideo.py
     文件        1593  2019-07-04 22:46  pyVideo\pyVideo\pyVideo.pyproj
     文件         612  2019-07-04 22:49  pyVideo\pyVideo\pyVideo.ui
     文件         861  2019-07-04 22:50  pyVideo\pyVideo\ui.py

评论

共有 条评论

相关资源