Najeebsk

VLC-PLAYER2.py

Mar 1st, 2024
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.90 KB | None | 0 0
  1. import tkinter as tk
  2. import vlc
  3.  
  4. class VideoPlayer:
  5.     def __init__(self, root):
  6.         self.root = root
  7.         self.instance = vlc.Instance('--no-xlib')  
  8.         self.player = self.instance.media_player_new()
  9.         self.player.set_fullscreen(True)
  10.  
  11.         self.main_frame = tk.Frame(root)
  12.         self.main_frame.pack(fill="both", expand=True)
  13.  
  14.         # Add big title label with custom font and color
  15.         self.title_label = tk.Label(self.main_frame, text="NAJEEB VIDEO PLAYER", font=("Arial", 24, "bold"), fg="blue")
  16.         self.title_label.pack(pady=10)
  17.  
  18.         self.list_frame = tk.Frame(self.main_frame)
  19.         self.list_frame.pack(side="left", fill="both", expand=False)
  20.  
  21.         self.button_frame = tk.Frame(self.main_frame)
  22.         self.button_frame.pack(side="bottom", fill="x")
  23.  
  24.         self.lst = tk.Listbox(self.list_frame, width=30, height=20)
  25.         self.lst.pack(side="left", fill="both", expand=True)
  26.  
  27.         self.scrollbar = tk.Scrollbar(self.list_frame, orient="vertical")
  28.         self.scrollbar.config(command=self.lst.yview)
  29.         self.scrollbar.pack(side="right", fill="y")
  30.  
  31.         self.lst.config(yscrollcommand=self.scrollbar.set)
  32.  
  33.         self.play_button = tk.Button(self.button_frame, text="Play", command=self.play_video)
  34.         self.play_button.pack(side="left", padx=5, pady=5)
  35.  
  36.         self.stop_button = tk.Button(self.button_frame, text="Stop", command=self.stop_video)
  37.         self.stop_button.pack(side="left", padx=5, pady=5)
  38.  
  39.         self.prev_button = tk.Button(self.button_frame, text="Prev", command=self.prev_video)
  40.         self.prev_button.pack(side="left", padx=5, pady=5)
  41.  
  42.         self.next_button = tk.Button(self.button_frame, text="Next", command=self.next_video)
  43.         self.next_button.pack(side="left", padx=5, pady=5)
  44.  
  45.         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
  46.         self.player_position.pack(side="left", fill="x", padx=5, pady=5)
  47.  
  48.         self.current_video_label = tk.Label(root, text="No video selected")
  49.         self.current_video_label.pack(pady=5)
  50.  
  51.         self.player_frame = tk.Frame(self.main_frame)
  52.         self.player_frame.pack(side="right", fill="both", expand=True)
  53.  
  54.         self.lst.bind("<<ListboxSelect>>", self.show_video)
  55.  
  56.         self.insert_files()
  57.  
  58.     def insert_files(self):
  59.         try:
  60.             with open('VIDEOS.txt', 'r') as file:
  61.                 self.video_list = []
  62.                 for line in file:
  63.                     line = line.strip()
  64.                     if line.startswith("Title:"):
  65.                         title = line.split(": ")[1]
  66.                         self.lst.insert(tk.END, title)
  67.                         self.video_list.append(title)
  68.                     elif line:
  69.                         setattr(self, title, line)  # Store filepath as an attribute
  70.         except FileNotFoundError:
  71.             print("VIDEOS.txt not found.")
  72.  
  73.     def play_video(self):
  74.         if self.player.get_state() == vlc.State.Ended:
  75.             self.player.stop()
  76.         self.player.play()
  77.         self.current_video_label.config(text="Video playing")
  78.  
  79.     def show_video(self, event):
  80.         n = self.lst.curselection()
  81.         if n:
  82.             title = self.lst.get(n[0])
  83.             filepath = getattr(self, title, None)
  84.             if filepath:
  85.                 media = self.instance.media_new(filepath)
  86.                 self.player.set_media(media)
  87.  
  88.                 if self.player_frame.winfo_children():
  89.                     self.player_frame.winfo_children()[0].destroy()
  90.  
  91.                 self.player_frame.update()
  92.                 self.player.set_hwnd(self.player_frame.winfo_id())
  93.                 self.play_video()  # Automatically play the video when selected
  94.                 self.current_video_label.config(text="Current video: " + title)
  95.  
  96.     def stop_video(self):
  97.         self.player.stop()
  98.         self.current_video_label.config(text="Video stopped")
  99.  
  100.     def prev_video(self):
  101.         current_index = self.video_list.index(self.lst.get(tk.ACTIVE))
  102.         prev_index = current_index - 1 if current_index > 0 else len(self.video_list) - 1
  103.         self.lst.selection_clear(0, tk.END)
  104.         self.lst.selection_set(prev_index)
  105.         self.lst.activate(prev_index)
  106.         self.show_video(None)
  107.  
  108.     def next_video(self):
  109.         current_index = self.video_list.index(self.lst.get(tk.ACTIVE))
  110.         next_index = (current_index + 1) % len(self.video_list)
  111.         self.lst.selection_clear(0, tk.END)
  112.         self.lst.selection_set(next_index)
  113.         self.lst.activate(next_index)
  114.         self.show_video(None)
  115.  
  116.     def set_position(self, value):
  117.         self.player.set_position(float(value) / 100)
  118.  
  119. root = tk.Tk()
  120. root.geometry("800x600+300+50")
  121. #root.config(bg='green')
  122. root.title("Najeeb VLC Player")
  123. video_player = VideoPlayer(root)
  124. root.mainloop()
  125.  
Add Comment
Please, Sign In to add comment