|
| 1 | +import os |
| 2 | +import pygame |
| 3 | +import tkinter as tk |
| 4 | +from tkinter import filedialog |
| 5 | +from tkinter import ttk |
| 6 | + |
| 7 | +# Initialize pygame |
| 8 | +pygame.init() |
| 9 | + |
| 10 | +# Function to list video files in a directory |
| 11 | +def list_video_files(directory): |
| 12 | + video_files = [] |
| 13 | + for root, _, files in os.walk(directory): |
| 14 | + for file in files: |
| 15 | + if file.endswith((".mp4", ".avi", ".mkv")): |
| 16 | + video_files.append(os.path.join(root, file)) |
| 17 | + return video_files |
| 18 | + |
| 19 | +# Function to play video |
| 20 | +def play_video(): |
| 21 | + selected_item = video_listbox.curselection() |
| 22 | + if selected_item: |
| 23 | + index = int(selected_item[0]) |
| 24 | + video = pygame.movie.Movie(video_files[index]) |
| 25 | + video.set_display(video_display) |
| 26 | + video.play() |
| 27 | + |
| 28 | +# Function to pause video |
| 29 | +def pause_video(): |
| 30 | + pygame.mixer.music.pause() |
| 31 | + |
| 32 | +# Function to resume video |
| 33 | +def resume_video(): |
| 34 | + pygame.mixer.music.unpause() |
| 35 | + |
| 36 | +# Function to stop video |
| 37 | +def stop_video(): |
| 38 | + pygame.mixer.music.stop() |
| 39 | + |
| 40 | +# Function to open a directory dialog and set the video directory |
| 41 | +def choose_directory(): |
| 42 | + global video_directory |
| 43 | + video_directory = filedialog.askdirectory() |
| 44 | + video_files = list_video_files(video_directory) |
| 45 | + video_listbox.delete(0, tk.END) |
| 46 | + for file in video_files: |
| 47 | + video_listbox.insert(tk.END, os.path.basename(file)) |
| 48 | + |
| 49 | +# Create a tkinter window |
| 50 | +root = tk.Tk() |
| 51 | +# Adjust size |
| 52 | +root.geometry("420x300") |
| 53 | + |
| 54 | +# set minimum window size value |
| 55 | +root.minsize(420, 300) |
| 56 | + |
| 57 | +# set maximum window size value |
| 58 | +root.maxsize(420, 300) |
| 59 | +root.title("Video Player") |
| 60 | + |
| 61 | +# Create and configure a frame for buttons |
| 62 | +button_frame = ttk.Frame(root) |
| 63 | +button_frame.grid(row=1, column=0, padx=20, pady=10) |
| 64 | + |
| 65 | +# Create buttons |
| 66 | +play_button = ttk.Button(button_frame, text="Play", command=play_video) |
| 67 | +pause_button = ttk.Button(button_frame, text="Pause", command=pause_video) |
| 68 | +resume_button = ttk.Button(button_frame, text="Resume", command=resume_video) |
| 69 | +stop_button = ttk.Button(button_frame, text="Stop", command=stop_video) |
| 70 | + |
| 71 | +# Grid layout for buttons |
| 72 | +play_button.grid(row=0, column=0, padx=10) |
| 73 | +pause_button.grid(row=0, column=1, padx=10) |
| 74 | +resume_button.grid(row=0, column=2, padx=10) |
| 75 | +stop_button.grid(row=0, column=3, padx=10) |
| 76 | + |
| 77 | +# Create a frame for the video list |
| 78 | +list_frame = ttk.Frame(root) |
| 79 | +list_frame.grid(row=0, column=0, padx=20, pady=10) |
| 80 | + |
| 81 | +# Create a listbox to display video files |
| 82 | +video_listbox = tk.Listbox(list_frame, selectmode=tk.SINGLE, width=50) |
| 83 | +video_listbox.pack() |
| 84 | + |
| 85 | +# Create a button to choose the video directory |
| 86 | +choose_button = ttk.Button(list_frame, text="Choose Video Directory", command=choose_directory) |
| 87 | +choose_button.pack() |
| 88 | + |
| 89 | +# Initialize the video directory |
| 90 | +video_directory = "" |
| 91 | + |
| 92 | +# Create a Pygame display for video playback |
| 93 | +video_display = pygame.display.set_mode((640, 480)) |
| 94 | + |
| 95 | +# Run the tkinter main loop |
| 96 | +root.mainloop() |
0 commit comments