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') # Add this line for Windows support
- self.player = self.instance.media_player_new()
- self.player.set_fullscreen(True)
- self.frame = tk.Frame(root, bg="#336699")
- self.frame.pack(side="left", fill="both", expand=True)
- self.player_frame = tk.Frame(root, width=600, height=400, bg="#336699")
- self.player_frame.pack(side="right", fill="both", expand=True)
- self.status_label = tk.Label(self.frame, text="", fg="green", bg="#336699")
- self.status_label.pack()
- self.control_frame = tk.Frame(self.frame, bg="#336699")
- self.control_frame.pack(side="bottom", fill="x")
- self.play_button = tk.Button(self.control_frame, text="Play", command=self.play_video, fg="white", bg="#6699CC")
- self.play_button.pack(side="left", padx=5)
- self.stop_button = tk.Button(self.control_frame, text="Stop", command=self.stop_video, fg="white", bg="#6699CC")
- self.stop_button.pack(side="left", padx=5)
- self.mute_button = tk.Button(self.control_frame, text="Mute", command=self.toggle_mute, fg="white", bg="#6699CC")
- self.mute_button.pack(side="left", padx=5)
- self.fullscreen_button = tk.Button(self.control_frame, text="Fullscreen", command=self.toggle_fullscreen, fg="white", bg="#6699CC")
- self.fullscreen_button.pack(side="left", padx=5)
- self.seek_slider = tk.Scale(self.control_frame, from_=0, to=100, orient="horizontal", command=self.seek_video, bg="#336699")
- self.seek_slider.pack(side="left", padx=5)
- self.lst_frame = tk.Frame(self.frame, bg="#336699")
- self.lst_frame.pack(side="bottom", fill="both", expand=True)
- self.search_entry = tk.Entry(self.lst_frame, bg="#FFFFFF")
- self.search_entry.pack(side="top", fill="x")
- self.search_entry.bind('<KeyRelease>', self.search_channels)
- self.lst = tk.Listbox(self.lst_frame, width=20, height=20, bg="#FFFFFF") # Adjust width as needed
- self.lst.pack(side="left", fill="both", expand=True)
- self.scrollbar = tk.Scrollbar(self.lst_frame, orient="vertical", command=self.lst.yview)
- self.scrollbar.pack(side="right", fill="y")
- self.lst.config(yscrollcommand=self.scrollbar.set)
- self.lst.bind("<<ListboxSelect>>", self.play_selected_channel)
- self.read_playlist()
- self.current_channel_index = 0
- self.root.bind("<Escape>", self.exit_fullscreen)
- def read_playlist(self):
- try:
- with open("playlist.m3u8", "r", encoding="utf-8") as file:
- self.channels = {}
- channel_name = None
- for line in file:
- if line.startswith("#EXTINF:"):
- channel_name = line.split(',')[1].strip()
- elif channel_name:
- url = line.strip()
- self.channels[channel_name] = url
- self.lst.insert(tk.END, channel_name)
- channel_name = None
- except FileNotFoundError:
- self.status_label.config(text="Playlist not found", fg="red")
- def search_channels(self, event):
- query = self.search_entry.get().lower()
- self.lst.delete(0, tk.END)
- for channel_name, url in self.channels.items():
- if query in channel_name.lower():
- self.lst.insert(tk.END, channel_name)
- def play_selected_channel(self, event):
- selection = self.lst.curselection()
- if selection:
- channel_name = self.lst.get(selection[0])
- self.play_channel(channel_name)
- def play_video(self):
- self.player.play()
- self.status_label.config(text="Playing", fg="white")
- def stop_video(self):
- self.player.stop()
- self.status_label.config(text="Stopped", fg="red")
- def toggle_mute(self):
- if self.player.audio_get_mute():
- self.player.audio_set_mute(False)
- self.mute_button.config(text="Mute", bg="#6699CC")
- else:
- self.player.audio_set_mute(True)
- self.mute_button.config(text="Unmute", bg="#FF0000")
- def toggle_fullscreen(self):
- if self.player.get_fullscreen():
- self.player.set_fullscreen(False)
- self.fullscreen_button.config(text="Fullscreen")
- self.root.attributes("-fullscreen", False)
- self.frame.pack(side="left", fill="both", expand=True)
- self.player_frame.pack(side="right", fill="both", expand=True)
- else:
- self.player.set_fullscreen(True)
- self.fullscreen_button.config(text="Exit Fullscreen")
- self.root.attributes("-fullscreen", True)
- self.frame.pack_forget()
- self.player_frame.pack(fill="both", expand=True)
- def exit_fullscreen(self, event):
- if self.player.get_fullscreen():
- self.toggle_fullscreen()
- def play_channel(self, channel_name):
- url = self.channels.get(channel_name)
- if url:
- try:
- media = self.instance.media_new(url)
- 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.player.play()
- self.status_label.config(text=f"Playing {channel_name}", fg="white")
- except Exception as e:
- self.status_label.config(text="Failed to play", fg="red")
- else:
- self.status_label.config(text="Channel not found", fg="red")
- def seek_video(self, value):
- if self.player.get_length() > 0:
- seek_position = int(value) * self.player.get_length() // 100
- self.player.set_time(seek_position)
- root = tk.Tk()
- root.title("NAJEEB IPTV PLAYER")
- root.config(bg='#336699')
- root.geometry("800x600+300+50")
- video_player = VideoPlayer(root)
- root.mainloop()
Add Comment
Please, Sign In to add comment