Java - Problemas con reproductor de mp3

 
Vista:

Problemas con reproductor de mp3

Publicado por Alejandro (1 intervención) el 28/05/2021 19:45:39
Tengo un pequeño reproductor de archivos mp3 hecho en Eclipse y cuando lo corro desde eclipse funciona perfecto pero si hago el jar y lo ejecuto desde ahí no funciona el audio, alguien sabe por qué?

adjunto el código
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
import java.io.File;
 
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
 
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
 
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JSlider;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
 
public class TocaDisco extends JFrame
{
 
	private JPanel contentPane;
	private JTextField TxtNombre;
	private double vol;
 
	/**
	 * Create the frame.
	 */
	public TocaDisco()
	{
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 640, 131);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
 
		JLabel lblNombreDeLa = new JLabel("Nombre de la cancion");
		lblNombreDeLa.setFont(new Font("Arial", Font.PLAIN, 12));
		lblNombreDeLa.setBounds(10, 11, 135, 14);
		contentPane.add(lblNombreDeLa);
 
		Disco tocar = new Disco();
 
		TxtNombre = new JTextField();
		TxtNombre.setFont(new Font("Arial", Font.PLAIN, 12));
		TxtNombre.setBounds(164, 8, 437, 20);
		contentPane.add(TxtNombre);
		TxtNombre.setColumns(10);
 
		Dimension pantalla = Toolkit.getDefaultToolkit().getScreenSize();
		int ancho = pantalla.width /2;
		int alto = pantalla.height/2;
		setLocation(ancho-640/2,alto-131/2);
 
		JButton btnNewButton = new JButton("");
		btnNewButton.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				tocar.Tocar();
			}
		});
		btnNewButton.setIcon(new ImageIcon(TocaDisco.class.getResource("/imagenes/tocar.jpg")));
		btnNewButton.setBounds(20, 36, 50, 50);
		contentPane.add(btnNewButton);
 
		JButton btnNewButton_1 = new JButton("");
		btnNewButton_1.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				tocar.Pausa();
			}
		});
		btnNewButton_1.setIcon(new ImageIcon(TocaDisco.class.getResource("/imagenes/pausa.jpg")));
		btnNewButton_1.setBounds(105, 36, 50, 50);
		contentPane.add(btnNewButton_1);
 
		JButton btnNewButton_2 = new JButton("");
		btnNewButton_2.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				tocar.Parar();
			}
		});
		btnNewButton_2.setIcon(new ImageIcon(TocaDisco.class.getResource("/imagenes/Pare.jpg")));
		btnNewButton_2.setBounds(188, 36, 50, 50);
		contentPane.add(btnNewButton_2);
 
		JSlider deslisa = new JSlider();
		deslisa.setVisible(false);
		deslisa.setValue(0);
		deslisa.setMaximum(6);
		deslisa.addChangeListener(new ChangeListener()
		{
			public void stateChanged(ChangeEvent e)
			{
				vol=deslisa.getValue();
				JOptionPane.showMessageDialog(null, "El valor es "+vol);
				tocar.Volumen(vol);
			}
		});
		deslisa.setBounds(361, 44, 200, 26);
		contentPane.add(deslisa);
 
		JLabel lblNewLabel = new JLabel("Volumen");
		lblNewLabel.setVisible(false);
		lblNewLabel.setFont(new Font("Arial", Font.PLAIN, 12));
		lblNewLabel.setBounds(248, 56, 103, 14);
		contentPane.add(lblNewLabel);
 
		JFileChooser cuadro = new JFileChooser();
		File dir = new File(Declaraciones.RutaDisco+"/");
		cuadro.setCurrentDirectory(dir);
		int res=cuadro.showOpenDialog(cuadro);
 
		if (res == JFileChooser.APPROVE_OPTION)
		{
			TxtNombre.setText(cuadro.getSelectedFile().toString());
			tocar.Abrir(cuadro.getSelectedFile().getAbsolutePath());
			vol=tocar.getVolunen();
			deslisa.setValue((int)vol);
			tocar.Tocar();
		}
	}
}

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
import java.io.File;
 
import javazoom.jlgui.basicplayer.BasicPlayer;
import javazoom.jlgui.basicplayer.BasicPlayerException;
public class Disco
{
	public BasicPlayer tocar;
	double volumen=0;
	public Disco()
	{
		tocar = new BasicPlayer();
		volumen=tocar.getGainValue();
	}
	public boolean Abrir(String ruta)
	{
		File archi = new File(ruta);
		try
		{
			tocar.open(archi);
			return true;
		}
		catch (BasicPlayerException e)
		{
			return false;
		}
	}
	public boolean Tocar()
	{
		try
		{
			if ( tocar.getStatus() == 1)
			{
				tocar.resume();
			}
			else
			{
				tocar.play();
			}
			return true;
		}
		catch (BasicPlayerException e)
		{
			return false;
		}
	}
	public boolean Parar()
	{
		try
		{
			if (tocar.getStatus() == 1 || tocar.getStatus() == 0)
			{
				tocar.stop();
			}
			return true;
		}
		catch (BasicPlayerException e)
		{
			return false;
		}
	}
	public boolean Pausa()
	{
		try
		{
			if (tocar.getStatus() == 0)
			{
				tocar.pause();
			}
			return true;
		}
		catch (BasicPlayerException e)
		{
			return false;
		}
	}
	public boolean Volumen(double vol)
	{
		try
		{
			tocar.setGain(vol);
			return true;
		}
		catch (BasicPlayerException e)
		{
			return false;
		}
	}
	public double getVolunen()
	{
		return volumen;
	}
}
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