写一个视频播放器的代码
时间: 2023-12-01 21:26:11 浏览: 38
这是一个简单的视频播放器的代码,基于Python的Tkinter库和VLC插件:
```python
import tkinter as tk
import vlc
class VideoPlayer:
def __init__(self, master):
self.master = master
self.master.title("视频播放器")
self.instance = vlc.Instance()
self.player = self.instance.media_player_new()
self.player.set_fullscreen(True)
self.player.set_hwnd(self.master.winfo_id())
self.frame = tk.Frame(self.master, bg='black')
self.frame.pack(fill=tk.BOTH, expand=1)
self.play_button = tk.Button(self.frame, text='播放', command=self.play)
self.play_button.pack(side=tk.LEFT)
self.pause_button = tk.Button(self.frame, text='暂停', command=self.pause)
self.pause_button.pack(side=tk.LEFT)
self.stop_button = tk.Button(self.frame, text='停止', command=self.stop)
self.stop_button.pack(side=tk.LEFT)
self.volume_scale = tk.Scale(self.frame, from_=0, to=100, orient=tk.HORIZONTAL, command=self.set_volume)
self.volume_scale.set(50)
self.volume_scale.pack(side=tk.LEFT, fill=tk.BOTH, expand=1)
def play(self):
media = self.instance.media_new('video.mp4')
self.player.set_media(media)
self.player.play()
def pause(self):
if self.player.is_playing():
self.player.pause()
else:
self.player.play()
def stop(self):
self.player.stop()
def set_volume(self, val):
self.player.audio_set_volume(int(val))
if __name__ == '__main__':
root = tk.Tk()
player = VideoPlayer(root)
root.mainloop()
```
注意:这个代码需要安装VLC插件,可以从官网下载安装。在代码中,`video.mp4`是视频的文件名,需要将其替换为你自己的视频文件名。
阅读全文