Implemented radio player
This commit is contained in:
parent
5d893092b3
commit
197de5380a
|
@ -9,5 +9,3 @@ def main():
|
|||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
#self.tasks["scrapper"].start(self.scrapper.start_scraping)
|
|
@ -0,0 +1 @@
|
|||
http://uk2.internet-radio.com:8024/
|
|
@ -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}")
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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"""
|
||||
|
|
Binary file not shown.
|
@ -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,9 +130,12 @@ 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)
|
||||
text_widget.pack(fill=ctk.BOTH, expand=True, padx=10, pady=10)
|
||||
|
@ -250,3 +255,54 @@ class CenteredWindow(ctk.CTk):
|
|||
|
||||
def dummy_action(self):
|
||||
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)
|
Loading…
Reference in New Issue