|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Member
Iscritto dal: Nov 2006
Città: Vigonovo
Messaggi: 108
|
[JAVA] Player MP3
salve ho creato questo semplice player ma non riesco a metterlo in pausa, elenco di seguito il codice:
Codice:
package player; import javax.media.*; import javax.swing.*; import javax.swing.event.*; import java.io.File; import java.awt.*; import java.awt.event.*; public class Main{ public static void main(String[] args){ PL p=new PL(); p.setSize(300,300); p.setVisible(true); p.pack(); } } class PL extends Frame implements ActionListener,ChangeListener,WindowListener{ private JButton Play,Stop,Muto,Open; private Panel p1,p; private PlayerThread pt; private boolean statoMute; private File aperto; private JSlider slider; private static final int VOL_MIN=0; private static final int VOL_INIT=50; private static final int VOL_MAX=100; public PL(){ super("Audio Player"); p=new Panel(); aperto=null; slider=new JSlider(JSlider.HORIZONTAL,VOL_MIN,VOL_MAX,VOL_INIT); p.add(new Label("Audio Player")); p1=new Panel(); Play=new JButton("Play"); Stop=new JButton("Stop"); Open=new JButton("^"); Play.addActionListener(this); Stop.addActionListener(this); Open.addActionListener(this); slider.addChangeListener(this); addWindowListener(this); Muto=new JButton("Mute"); Muto.addActionListener(this); setLayout(new GridLayout(2,1)); p1.add(Open); p1.add(Play); p1.add(Stop); p1.add(slider); p1.add(Muto); pt=null; statoMute=false; add(p); add(p1); } public void actionPerformed(ActionEvent e) { String nomeBottone=e.getActionCommand(); if(nomeBottone.equals("^")) aperto=OpenFile(); if(nomeBottone.equals("Play")){ if(aperto!=null){ pt.playerPause(); } else{ aperto=OpenFile(); pt=new PlayerThread(aperto); pt.start(); } } if(nomeBottone.equals("Stop")&&pt!=null){ pt.playerStop(); } if(nomeBottone.equals("Mute")){ statoMute=!statoMute; pt.playerMute(statoMute); } } public File OpenFile(){ FileDialog fd=new FileDialog(this,"File",FileDialog.LOAD); fd.setVisible(true); File f = new File (fd.getDirectory(), fd.getFile()); fd.dispose(); return f; } public void stateChanged(ChangeEvent e) { JSlider source = (JSlider)e.getSource(); pt.playerVolume((float)source.getValue()); } public void windowOpened(WindowEvent e) {} public void windowClosing(WindowEvent e) { pt.playerStop(); System.exit(0); } public void windowClosed(WindowEvent e) {} public void windowIconified(WindowEvent e) {} public void windowDeiconified(WindowEvent e) {} public void windowActivated(WindowEvent e) {} public void windowDeactivated(WindowEvent e) {} } class PlayerThread extends Thread{ private Player p; private File file; PlayerThread(File file){ this.file=file; p=null; } void playerStart(){ try { p = Manager.createPlayer(file.toURL()); p.start(); } catch (Exception ex) { ex.printStackTrace(); } } void playerPause(){ try{ if(playerState()) synchronized(p){ p.wait(); } else synchronized(p){ p.notifyAll(); } } catch(Exception ex){ ex.printStackTrace(); } } boolean playerState(){ if(p.getState()==600) return true; else return false; } void playerStop(){ p.stop(); p.close(); } void playerMute(boolean stato){ p.getGainControl().setMute(stato); } void playerVolume(float level){ p.getGainControl().setLevel(level/100); } public void run(){ playerStart(); } } potete aiutarmi ?
__________________
Intel Core i7 3770 - ASUS P8Z77-V LE Plus - RAM DDR 3 Kingston Hyper-X 16GB 1600 Mhz - EVGA GeForce GTX 1070 FTW - SSD Samsung 750 EVO + 320GB WD Caviar Blue - Ali Corsair CX600 - Case CM HAF 932 Advanced |
![]() |
![]() |
![]() |
#2 |
Member
Iscritto dal: Nov 2006
Città: Vigonovo
Messaggi: 108
|
UP
__________________
Intel Core i7 3770 - ASUS P8Z77-V LE Plus - RAM DDR 3 Kingston Hyper-X 16GB 1600 Mhz - EVGA GeForce GTX 1070 FTW - SSD Samsung 750 EVO + 320GB WD Caviar Blue - Ali Corsair CX600 - Case CM HAF 932 Advanced |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 00:22.