Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- import vlc
- class VideoPlayer:
- def __init__(self, root):
- self.root = root
- self.instance = vlc.Instance('--no-xlib')
- self.player = self.instance.media_player_new()
- self.player.set_fullscreen(True)
- self.main_frame = tk.Frame(root)
- self.main_frame.pack(fill="both", expand=True)
- # Add big title label with custom font and color
- self.title_label = tk.Label(self.main_frame, text="NAJEEB VIDEO PLAYER", font=("Arial", 24, "bold"), fg="blue")
- self.title_label.pack(pady=10)
- self.list_frame = tk.Frame(self.main_frame)
- self.list_frame.pack(side="left", fill="both", expand=False)
- self.button_frame = tk.Frame(self.main_frame)
- self.button_frame.pack(side="bottom", fill="x")
- self.lst = tk.Listbox(self.list_frame, width=30, height=20)
- self.lst.pack(side="left", fill="both", expand=True)
- self.scrollbar = tk.Scrollbar(self.list_frame, orient="vertical")
- self.scrollbar.config(command=self.lst.yview)
- self.scrollbar.pack(side="right", fill="y")
- self.lst.config(yscrollcommand=self.scrollbar.set)
- self.play_button = tk.Button(self.button_frame, text="Play", command=self.play_video)
- self.play_button.pack(side="left", padx=5, pady=5)
- self.stop_button = tk.Button(self.button_frame, text="Stop", command=self.stop_video)
- self.stop_button.pack(side="left", padx=5, pady=5)
- self.prev_button = tk.Button(self.button_frame, text="Prev", command=self.prev_video)
- self.prev_button.pack(side="left", padx=5, pady=5)
- self.next_button = tk.Button(self.button_frame, text="Next", command=self.next_video)
- self.next_button.pack(side="left", padx=5, pady=5)
- self.player_position = tk.Scale(self.button_frame, from_=0, to=100, orient="horizontal", command=self.set_position, length=400) # Adjust the length as needed
- self.player_position.pack(side="left", fill="x", padx=5, pady=5)
- self.current_video_label = tk.Label(root, text="No video selected")
- self.current_video_label.pack(pady=5)
- self.player_frame = tk.Frame(self.main_frame)
- self.player_frame.pack(side="right", fill="both", expand=True)
- self.lst.bind("<<ListboxSelect>>", self.show_video)
- self.insert_files()
- def insert_files(self):
- try:
- with open('VIDEOS.txt', 'r') as file:
- self.video_list = []
- for line in file:
- line = line.strip()
- if line.startswith("Title:"):
- title = line.split(": ")[1]
- self.lst.insert(tk.END, title)
- self.video_list.append(title)
- elif line:
- setattr(self, title, line) # Store filepath as an attribute
- except FileNotFoundError:
- print("VIDEOS.txt not found.")
- def play_video(self):
- if self.player.get_state() == vlc.State.Ended:
- self.player.stop()
- self.player.play()
- self.current_video_label.config(text="Video playing")
- def show_video(self, event):
- n = self.lst.curselection()
- if n:
- title = self.lst.get(n[0])
- filepath = getattr(self, title, None)
- if filepath:
- media = self.instance.media_new(filepath)
- self.player.set_media(media)
- if self.player_frame.winfo_children():
- self.player_frame.winfo_children()[0].destroy()
- self.player_frame.update()
- self.player.set_hwnd(self.player_frame.winfo_id())
- self.play_video() # Automatically play the video when selected
- self.current_video_label.config(text="Current video: " + title)
- def stop_video(self):
- self.player.stop()
- self.current_video_label.config(text="Video stopped")
- def prev_video(self):
- current_index = self.video_list.index(self.lst.get(tk.ACTIVE))
- prev_index = current_index - 1 if current_index > 0 else len(self.video_list) - 1
- self.lst.selection_clear(0, tk.END)
- self.lst.selection_set(prev_index)
- self.lst.activate(prev_index)
- self.show_video(None)
- def next_video(self):
- current_index = self.video_list.index(self.lst.get(tk.ACTIVE))
- next_index = (current_index + 1) % len(self.video_list)
- self.lst.selection_clear(0, tk.END)
- self.lst.selection_set(next_index)
- self.lst.activate(next_index)
- self.show_video(None)
- def set_position(self, value):
- self.player.set_position(float(value) / 100)
- root = tk.Tk()
- root.geometry("800x600+300+50")
- #root.config(bg='green')
- root.title("Najeeb VLC Player")
- video_player = VideoPlayer(root)
- root.mainloop()
Add Comment
Please, Sign In to add comment