用pyqt5写一个视频播放的界面
时间: 2023-10-10 07:07:50 浏览: 182
用qt5写的视频播放器
当然可以!以下是一个使用PyQt5编写的简单视频播放界面的示例代码:
```python
import sys
from PyQt5.QtCore import Qt, QDir
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QLabel, QVBoxLayout, QPushButton, QFileDialog, QSlider, QHBoxLayout, QStyle, QSizePolicy, QStatusBar
from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent
from PyQt5.QtMultimediaWidgets import QVideoWidget
class VideoPlayer(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("视频播放器")
self.setGeometry(100, 100, 800, 600)
self.mediaPlayer = QMediaPlayer(None, QMediaPlayer.VideoSurface)
videoWidget = QVideoWidget()
self.setCentralWidget(videoWidget)
self.mediaPlayer.setVideoOutput(videoWidget)
self.statusBar = QStatusBar()
self.setStatusBar(self.statusBar)
openButton = QPushButton("打开视频")
openButton.clicked.connect(self.openFile)
self.playButton = QPushButton()
self.playButton.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay))
self.playButton.clicked.connect(self.play)
self.positionSlider = QSlider(Qt.Horizontal)
self.positionSlider.setRange(0, 0)
self.positionSlider.sliderMoved.connect(self.setPosition)
controlLayout = QHBoxLayout()
controlLayout.setContentsMargins(0, 0, 0, 0)
controlLayout.addWidget(openButton)
controlLayout.addWidget(self.playButton)
controlLayout.addWidget(self.positionSlider)
layout = QVBoxLayout()
layout.addWidget(videoWidget)
layout.addLayout(controlLayout)
container = QWidget()
container.setLayout(layout)
self.setCentralWidget(container)
self.mediaPlayer.stateChanged.connect(self.mediaStateChanged)
self.mediaPlayer.positionChanged
阅读全文