python视频播放器软件代码
previous_button = tk.Button(root, background=‘orange’, text=“上一首”, command=previous_video)next_button = tk.Button(root, background=‘orange’, text=“下一首”, command=next_video)stop_button = tk.Button(root
·
import tkinter as tk
from tkinter import filedialog
from moviepy.editor import VideoFileClip
current_video_index = 0
video_paths = []
playing_video = False
video_clip = None
def play_video():
global current_video_index, playing_video, video_clip
file_path = video_paths[current_video_index]
video_clip = VideoFileClip(file_path)
video_clip.preview()
playing_video = True
def pause_video():
global playing_video, video_clip
if playing_video and video_clip:
video_clip.preview(autoplay=False)
playing_video = False
def continue_video():
global playing_video, video_clip
if not playing_video and video_clip:
video_clip.preview(autoplay=True)
playing_video = True
def stop_video():
global playing_video, video_clip
if video_clip:
video_clip.close()
playing_video = False
video_clip = None
def next_video():
global current_video_index
if current_video_index < len(video_paths) - 1:
current_video_index += 1
else:
current_video_index = 0
play_video()
def previous_video():
global current_video_index
if current_video_index > 0:
current_video_index -= 1
else:
current_video_index = len(video_paths) - 1
play_video()
def open_file():
file_paths = filedialog.askopenfilenames(filetypes=[("MP4 Files", "*.mp4"), ("AVI Files", "*.avi")])
for file_path in file_paths:
video_paths.append(file_path)
video_list.insert(tk.END, file_path)
root = tk.Tk()
root.title("视频播放器")
video_list = tk.Listbox(root, background='cyan', selectmode=tk.MULTIPLE)
video_list.place(x=50, y=30, width=300, height=300)
play_button = tk.Button(root, background='green', text="播放", command=play_video)
play_button.place(x=400, y=80, width=150, height=100)
pause_button = tk.Button(root, background='yellow', text="暂停", command=pause_video)
pause_button.place(x=600, y=80, width=150, height=100)
continue_button = tk.Button(root, background='blue', text="继续", command=continue_video)
continue_button.place(x=600, y=200, width=150, height=100)
stop_button = tk.Button(root, background='red', text="停止", command=stop_video)
stop_button.place(x=400, y=200, width=150, height=100)
previous_button = tk.Button(root, background='orange', text="上一首", command=previous_video)
previous_button.place(x=800, y=80, width=150, height=100)
next_button = tk.Button(root, background='orange', text="下一首", command=next_video)
next_button.place(x=800, y=200, width=150, height=100)
open_button = tk.Button(root, background='purple', text="打开文件", command=open_file)
open_button.place(x=450, y=400, width=200, height=100)
root.mainloop()
视频播放器组件
pip install pygame
pip install moviepy
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐
所有评论(0)