diff --git a/src/main.py b/src/main.py index 68495be..2e8efb1 100644 --- a/src/main.py +++ b/src/main.py @@ -9,5 +9,3 @@ def main(): if __name__ == "__main__": main() - - #self.tasks["scrapper"].start(self.scrapper.start_scraping) \ No newline at end of file diff --git a/src/resources/internet-radio.com.playlist.m3u b/src/resources/internet-radio.com.playlist.m3u new file mode 100644 index 0000000..7f48395 --- /dev/null +++ b/src/resources/internet-radio.com.playlist.m3u @@ -0,0 +1 @@ +http://uk2.internet-radio.com:8024/ diff --git a/src/services/Radio_Player.py b/src/services/Radio_Player.py new file mode 100644 index 0000000..428b769 --- /dev/null +++ b/src/services/Radio_Player.py @@ -0,0 +1,38 @@ +import vlc +import time +from services.threaden_task import ThreadenTask + +class RadioPlayer: + def __init__(self): + self.player = vlc.MediaPlayer() + self.thread_task = ThreadenTask() + self.running = False + + def play(self, url): + """Reproduce la emisora de radio desde la URL proporcionada.""" + try: + if self.running: + self.stop() + self.thread_task.start(self.play_radio, url) + self.running = True + except Exception as e: + print(f"Error al reproducir la emisora: {e}") + + def play_radio(self, url): + """Método interno para manejar la reproducción de la radio.""" + try: + self.player.set_media(vlc.Media(url)) + self.player.play() + while self.thread_task.running: + time.sleep(0.1) + except Exception as e: + print(f"Error en la reproducción de la radio: {e}") + + def stop(self): + """Detiene la reproducción de la emisora de radio.""" + try: + self.thread_task.stop() + self.player.stop() + self.running = False + except Exception as e: + print(f"Error al detener la reproducción: {e}") \ No newline at end of file diff --git a/src/services/__pycache__/Radio_Player.cpython-313.pyc b/src/services/__pycache__/Radio_Player.cpython-313.pyc new file mode 100644 index 0000000..a2bbd35 Binary files /dev/null and b/src/services/__pycache__/Radio_Player.cpython-313.pyc differ diff --git a/src/services/__pycache__/scrapper.cpython-313.pyc b/src/services/__pycache__/scrapper.cpython-313.pyc index a37199b..6c9e88b 100644 Binary files a/src/services/__pycache__/scrapper.cpython-313.pyc and b/src/services/__pycache__/scrapper.cpython-313.pyc differ diff --git a/src/services/__pycache__/system_monitor.cpython-313.pyc b/src/services/__pycache__/system_monitor.cpython-313.pyc index 489773b..0fd80e4 100644 Binary files a/src/services/__pycache__/system_monitor.cpython-313.pyc and b/src/services/__pycache__/system_monitor.cpython-313.pyc differ diff --git a/src/services/__pycache__/threads_manager.cpython-313.pyc b/src/services/__pycache__/threads_manager.cpython-313.pyc index 394c7df..103a7ae 100644 Binary files a/src/services/__pycache__/threads_manager.cpython-313.pyc and b/src/services/__pycache__/threads_manager.cpython-313.pyc differ diff --git a/src/services/threads_manager.py b/src/services/threads_manager.py index 3daed0c..051b9d3 100644 --- a/src/services/threads_manager.py +++ b/src/services/threads_manager.py @@ -7,23 +7,33 @@ from services.threaden_task import ThreadenTask from services.system_monitor import SystemMonitor from services.tetris_game import TetrisGame from services.scrapper import Scrapper +from services.Radio_Player import RadioPlayer class ThreadsManager: """Constructor""" def __init__(self, ui_instance): self.ui_instance = ui_instance self.system_monitor = None + self.radio_player = RadioPlayer() self.tasks = { "time": ThreadenTask(), "temperature": ThreadenTask(), "emails":ThreadenTask(), "tetris_game":ThreadenTask(), "scrapper":ThreadenTask(), + "radio_player": ThreadenTask(), } self.system_monitor_tasks = {} self.scrapper = Scrapper(ui_instance) - + + def play_radio(self, url): + """Inicia la reproducción de radio en un hilo.""" + if not self.tasks["radio_player"].running: + self.tasks["radio_player"].start(self.radio_player.play, url) + def stop_radio(self): + """Detiene la reproducción de radio.""" + self.radio_player.stop() def set_system_monitor(self, system_monitor): """Asigna el monitor del sistema y crea sus tareas""" diff --git a/src/ui/__pycache__/centered_window.cpython-313.pyc b/src/ui/__pycache__/centered_window.cpython-313.pyc index 9421f41..02fb587 100644 Binary files a/src/ui/__pycache__/centered_window.cpython-313.pyc and b/src/ui/__pycache__/centered_window.cpython-313.pyc differ diff --git a/src/ui/centered_window.py b/src/ui/centered_window.py index da5bba4..b9db71f 100644 --- a/src/ui/centered_window.py +++ b/src/ui/centered_window.py @@ -4,11 +4,13 @@ import webbrowser import subprocess import os import threading +from tkinter import filedialog from services.threads_manager import ThreadsManager from services.processes_manager import ProcessManager from services.tetris_game import TetrisGame from services.system_monitor import SystemMonitor +from services.Radio_Player import RadioPlayer class CenteredWindow(ctk.CTk): @@ -128,8 +130,11 @@ class CenteredWindow(ctk.CTk): tab_view.pack(fill=ctk.BOTH, expand=True) # Crear pestañas y manejar contenido por separado - for tab_name in ["Scrapping", "Navegador", "Correos", "Juego", "Sistema"]: + for tab_name in ["Scrapping", "Radio", "Correos", "Juego", "Sistema"]: tab = tab_view.add(tab_name) + + if tab_name == "Radio": + self.create_radio_tab(tab) if tab_name == "Scrapping": text_widget = ctk.CTkTextbox(tab, width=500, height=400) @@ -249,4 +254,55 @@ class CenteredWindow(ctk.CTk): def dummy_action(self): - print("Acción no implementada") \ No newline at end of file + print("Acción no implementada") + + def create_radio_tab(self, tab): + """Crea la interfaz para la funcionalidad de emisoras de radio.""" + self.radio_player = self.thread_manager.radio_player + + # Lista de emisoras + radio_stations = { + "Box Radio UK": "http://uk2.internet-radio.com:8024/", + "Radio 2": "http://stream-url-2.com/stream", + "Radio 3": "http://stream-url-3.com/stream", + } + + # Dropdown para seleccionar emisora + self.selected_station = ctk.StringVar(value="Selecciona una emisora") + station_menu = ctk.CTkOptionMenu(tab, variable=self.selected_station, values=list(radio_stations.keys())) + station_menu.pack(pady=10) + + # Botón para reproducir + play_button = ctk.CTkButton( + tab, + text="Reproducir", + command=lambda: self.start_radio(radio_stations[self.selected_station.get()]) + ) + play_button.pack(pady=5) + + # Botón para detener + stop_button = ctk.CTkButton( + tab, + text="Detener", + command=self.stop_radio, + state=tk.DISABLED # Deshabilitado inicialmente + ) + stop_button.pack(pady=5) + + # Guardar referencias para habilitar/deshabilitar botones + self.radio_controls = {"play_button": play_button, "stop_button": stop_button} + + def start_radio(self, url): + """Inicia la reproducción de radio y actualiza los botones.""" + if url == "Selecciona una emisora": + tk.messagebox.showwarning("Advertencia", "Por favor, selecciona una emisora válida.") + return + self.radio_player.play(url) + self.radio_controls["play_button"].configure(state=tk.DISABLED) + self.radio_controls["stop_button"].configure(state=tk.NORMAL) + + def stop_radio(self): + """Detiene la reproducción de radio y actualiza los botones.""" + self.radio_player.stop() + self.radio_controls["play_button"].configure(state=tk.NORMAL) + self.radio_controls["stop_button"].configure(state=tk.DISABLED) \ No newline at end of file