import subprocess
import time

class BluetoothMusicPlayer:
    def connect(self, mac_address):
        # Connect to Bluetooth speaker
        connect_command = f"bluetoothctl << EOF\nconnect {mac_address}\nEOF"
        subprocess.run(connect_command, shell=True)

    def play(self, file_path):
        # Play song via VLC
        play_command = f"cvlc {file_path} &"
        subprocess.run(play_command, shell=True)

    def stop(self):
        # Stop VLC process
        stop_command = "pkill vlc"
        subprocess.run(stop_command, shell=True)

    def play_music(self, mac_address, file_path):
        self.connect(mac_address)
        self.play(file_path)

    def stop_music(self):
        self.stop()

   


# Example usage:
if __name__ == "__main__":
    bluetooth_player = BluetoothMusicPlayer()
    bluetooth_player.play_music("BA:89:44:1C:E8:26", "/home/user/2023-2024-projectone-mct-Maciej-Mitura/backend/helpers/RoxyDaddy.mp3")
