You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1006 B

import os
import tkinter as tk
from MediaPlayer import MediaPlayer
CLIENT_HOST = "localhost"
CLIENT_PORT = 9999
media_player = MediaPlayer(CLIENT_HOST, CLIENT_PORT)
def request_selected_song():
selected_song = song_listbox.get(song_listbox.curselection())
media_player.request_song(selected_song)
def stop_song():
media_player.stop_song()
root = tk.Tk()
root.title("Song Requestor")
song_listbox = tk.Listbox(root, height=10, width=50)
song_listbox.pack()
song_list = media_player.requestor.getSongList()
for song in song_list:
if song: # Check if song is not an empty string
song_listbox.insert(tk.END, song)
request_button = tk.Button(root, text="Play song", command=request_selected_song)
request_button.pack()
play_pause_button = tk.Button(root, text="Stop song", command=stop_song)
play_pause_button.pack()
def on_close():
media_player.stop_song()
os.remove('received_song.mid')
root.destroy()
root.protocol("WM_DELETE_WINDOW", on_close)
root.mainloop()

Powered by INFORMATICA.FP.EDU.ES.