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)
- self.frame.pack(side="left", fill="both", expand=True)
- self.player_frame = tk.Frame(root, width=600, height=400)
- self.player_frame.pack(side="right", fill="both", expand=True)
- self.status_label = tk.Label(self.frame, text="", fg="green")
- self.status_label.pack()
- self.control_frame = tk.Frame(self.frame)
- self.control_frame.pack(side="bottom", fill="x")
- self.play_button = tk.Button(self.control_frame, text="Play", command=self.play_video)
- self.play_button.pack(side="left", padx=5)
- self.stop_button = tk.Button(self.control_frame, text="Stop", command=self.stop_video)
- self.stop_button.pack(side="left", padx=5)
- self.seek_slider = tk.Scale(self.control_frame, from_=0, to=100, orient="horizontal", command=self.seek_video)
- self.seek_slider.pack(side="left", padx=5)
- self.lst_frame = tk.Frame(self.frame)
- self.lst_frame.pack(side="bottom", fill="both", expand=True)
- self.lst = tk.Listbox(self.lst_frame, width=20, height=20) # 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
- def read_playlist(self):
- try:
- with open("playlist.m3u8", "r") as file:
- lines = file.readlines()
- for line in lines:
- if line.startswith("#EXTINF:"):
- channel_name = line.split('group-title="')[1].split('"')[0]
- self.lst.insert(tk.END, channel_name)
- except FileNotFoundError:
- self.status_label.config(text="Playlist not found", fg="red")
- def play_selected_channel(self, event):
- selection = self.lst.curselection()
- if selection:
- channel_index = selection[0]
- self.play_channel(channel_index)
- def play_video(self):
- self.player.play()
- self.status_label.config(text="Playing", fg="green")
- def stop_video(self):
- self.player.stop()
- self.status_label.config(text="Stopped", fg="red")
- def play_channel(self, channel_index):
- try:
- with open("playlist.m3u8", "r") as file:
- lines = file.readlines()
- for i, line in enumerate(lines):
- if line.startswith("#EXTINF:"):
- if i // 2 == channel_index:
- stream_url = lines[i + 1].strip()
- media = self.instance.media_new(stream_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="Playing", fg="green")
- self.current_channel_index = channel_index
- return
- self.status_label.config(text="Channel not found", fg="red")
- except Exception as e:
- self.status_label.config(text="Failed to play", 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='green')
- root.geometry("800x600+300+50")
- video_player = VideoPlayer(root)
- root.mainloop()
Add Comment
Please, Sign In to add comment