projeto

mail@pastecode.io avatar
unknown
java
2 years ago
4.9 kB
2
Indexable
Never
import java.awt.event.*;
import ui.PlayerWindow;
import ui.AddSongWindow;
import java.util.ArrayList;



public class Player {
    ArrayList<String[]> listamusicas;
    private int count_musicas = 0;
    int id_anterior = 0;
    private Boolean tocando = false;
    private final PlayerWindow window;
    private AddSongWindow addSongWindow = null;


    public Player() {
        String windowTitle = "Tocador de música";


        ActionListener buttonListenerPlayNow = e -> {Tocar();};
        ActionListener buttonListenerRemove = e -> {RemoverMusica();};
        ActionListener buttonListenerAddSong = e -> {AdicionarMusica();};
        ActionListener buttonListenerPlayPause = e -> {Pausar();};
        ActionListener buttonListenerStop = e -> {parar();};
        ActionListener buttonListenerNext = e -> {proximo();            System.out.println("Clicou no Next");};
        ActionListener buttonListenerPrevious = e -> {anterior();       System.out.println("Clicou no Previous");};

        ActionListener buttonListenerShuffle = e -> {shuffle();         System.out.println("Clicou no Shuffle");};
        ActionListener buttonListenerRepeat = e -> {repetir();          System.out.println("Clicou no Listener Repeat");};


        MouseListener scrubberListenerClick = new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {
                System.out.println("O mouse está funcionando");
            }

            @Override
            public void mousePressed(MouseEvent e) {
                System.out.println("O mouse está funcionando");
            }

            @Override
            public void mouseReleased(MouseEvent e) {

            }

            @Override
            public void mouseEntered(MouseEvent e) {

            }

            @Override
            public void mouseExited(MouseEvent e) {

            }
        };
        MouseMotionListener scrubberListenerMotion = new MouseMotionListener() {
            @Override
            public void mouseDragged(MouseEvent e) {

            }

            @Override
            public void mouseMoved(MouseEvent e) {

            }
        };


        this.listamusicas = new ArrayList();
        this.window = new PlayerWindow(
                buttonListenerPlayNow, buttonListenerRemove,
                buttonListenerAddSong, buttonListenerPlayPause,
                buttonListenerStop, buttonListenerNext,
                buttonListenerPrevious, buttonListenerShuffle,
                buttonListenerRepeat, scrubberListenerClick,
                scrubberListenerMotion, windowTitle, this.listamusicas.toArray(new String[0][0])
        );


    }


    private void adicionarnoarray(String[] novamusica) {
        listamusicas.add(novamusica);


    }


    private void AdicionarMusica() { //
        ActionListener buttonListenerAddSongOK = e ->
        {
            this.listamusicas.add(this.addSongWindow.getSong());
            this.window.updateQueueList(this.listamusicas.toArray(new String[0][0])); };

        int id_atual = this.id_anterior + 1;
        this.id_anterior++;
        this.count_musicas++;

        AddSongWindow addSongWindow = new AddSongWindow(Integer.toString(id_atual), buttonListenerAddSongOK, this.window.getAddSongWindowListener());

        this.addSongWindow = addSongWindow;
    }

    private void RemoverMusica() {
        int id_selecionado = this.window.getSelectedSongID();


        for (int index = 0; index < count_musicas; index++) {
            String[] musica_temp = listamusicas.get(index);

            if  (musica_temp[6].equals(Integer.toString(id_selecionado) )) {

                this.listamusicas.remove(index);
                this.window.updateQueueList(this.listamusicas.toArray(new String[0][0]));}
        }


        count_musicas = count_musicas -1;
    }


    private void Tocar(){
        int id_buscado = this.window.getSelectedSongID();

        for (int index = 0; index < count_musicas; index++) {
            String[] musica_temp = listamusicas.get(index);

            if (musica_temp[6].equals(Integer.toString(id_buscado) )) {
                String[] musica = this.listamusicas.get(index);
                this.window.updatePlayingSongInfo(musica[0], musica[1], musica[2]);
            }
        }
        this.window.enableScrubberArea();
    }

    private void Pausar() {
        this.tocando = !this.tocando;
        this.window.updatePlayPauseButton(this.tocando);
    }





    private void parar() {
        this.window.resetMiniPlayer();
        tocando = false;
    }







    private void shuffle() {
    }

    private void repetir() {
    }

    private void proximo() {
    }

    private void anterior() {
    }






}