Java - ayuda con codigo java y libreria jgui

 
Vista:
sin imagen de perfil

ayuda con codigo java y libreria jgui

Publicado por Mijailo (1 intervención) el 02/03/2016 13:55:54
hola, estoy haciendo un reproductor de musica el cual funciona, tiene funcion de pausar, reanudar, parar, y un JFileChooser para seleccionar el archivo, lo que me gustaría agregar es una barra deslizable de tiempo para seleccionar el segundo o minuto del archivo de musica y un cronometro para contar la duracion este es el codigo y el link de donde descargue la librería:

http://www.javazoom.net/jlgui/sources.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package reproductor;
 
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
 
import javax.swing.*;
 
import javazoom.jlgui.basicplayer.BasicPlayer;
import javazoom.jlgui.basicplayer.BasicPlayerException;
 
 
public class Reproductor extends JFrame{
 
 
	String ruta;
 
 
	private JMenuBar menu;
    private JMenu men;
	private JFileChooser archivo;
	private JButton lol;
	private JButton abrir;
	private JButton stop;
	private JButton reiniciar;
	private JLabel salida;
 
 
	int contadorete = 0;
 
	Reproductor(){
 
		BasicPlayer player= new BasicPlayer(); // Llamo la clase de la libreria Basic Player, que reproduce
 
 
		setLayout(null);
 
		lol = new JButton("play");
		lol.setBounds(200,100,85,40);
		abrir = new JButton("abrir archivo");
		stop = new JButton ("parar");
		stop.setBounds(100,100,85,40);
		reiniciar = new JButton("reiniciar");
		reiniciar.setBounds(300,100,85,40);
 
		menu = new JMenuBar();
		men = new JMenu("opciones");
 
		menu.add(men);
		men.add(abrir);
		setJMenuBar(menu);
 
		salida = new JLabel();
		salida.setBounds(350, 50, 300, 40);
 
		archivo = new JFileChooser ();
 
		stop.addActionListener(new ActionListener (){
			public void actionPerformed(ActionEvent evento) {
				try {
					player.stop();
				} catch (BasicPlayerException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
 
		reiniciar.addActionListener(new ActionListener (){
			public void actionPerformed(ActionEvent evento) {
				try {
					player.stop();
					player.play();
				} catch (BasicPlayerException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
 
 
		abrir.addActionListener(new ActionListener (){
			public void actionPerformed(ActionEvent evento) {
 
				archivo.showOpenDialog(abrir);
				File abre=archivo.getSelectedFile();
 
				System.out.println("La ruta del fichero es: " + abre.getAbsolutePath());
 
				try {
 
	        player.open(new File(""+abre));// Dentro las "" va la ruta de tu archivo mp3.
	        player.play();
 
	       setTitle(""+abre);
	    } catch (BasicPlayerException ex) {
	        System.out.print("-------Error-----"+ex.getMessage());
	    }// Fin try
 
			}
		});
 
 
 
		lol.addActionListener(new ActionListener (){
			public void actionPerformed(ActionEvent evento) {
				contadorete ++;
 
				if(contadorete == 1){
					lol.setText("pausa");
 
					try {
						player.resume();
						player.play();
					} catch (BasicPlayerException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}// Llama al método Reproducir también existen los métodos  stop,resume.
 
 
 
				}
				if (contadorete == 2){
					lol.setText("play");
					contadorete = 0;
 
					try {
						player.pause();
					} catch (BasicPlayerException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}// Llama al método Reproducir también existen los métodos  stop,resume.
 
				}
 
			}
		});
 
 
    	this.add(lol);
    	this.add(stop);
    	this.add(reiniciar);
    	lol.setFocusable(false);
    	this.add(salida);
 
    	this.setResizable(false);
    	this.setSize(500,200);
    	this.setVisible(true);
    	this.setTitle("Reproductor");
    	this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
    	this.setLocationRelativeTo(null);
    }
 
}// Fin Clase
 
//y la clase principal
 
 
package reproductor;
 
public class Principal {
 
	public static void main(String[] args) {
		// TODO Auto-generated method stub
 
		Reproductor player = new Reproductor();
 
	}
 
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder