-
-
Save salimos/5606235 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this template, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package mp3player; | |
import java.io.FileInputStream; | |
import java.io.FileNotFoundException; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
import javazoom.jl.decoder.JavaLayerException; | |
import javazoom.jl.player.Player; | |
/** | |
* | |
* @author SAMSUNG | |
*/ | |
public class playerGUI extends javax.swing.JFrame { | |
Player mp3Lecteur; | |
int pos; | |
/** | |
* Creates new form playerGUI | |
*/ | |
public playerGUI() { | |
initComponents(); | |
} | |
public void play() throws JavaLayerException { | |
try { | |
FileInputStream mp3File = new FileInputStream("C:\\Users\\SAMSUNG\\Desktop\\Desktop\\mp3\\07. georgia on my mind.mp3"); | |
mp3Lecteur = new Player(mp3File); | |
} catch (FileNotFoundException ex) { | |
System.out.println("erreur de fichier mp3------->" + ex.getMessage()); | |
} | |
new Thread() { | |
public void run() { | |
try { | |
mp3Lecteur.play(); | |
} catch (JavaLayerException ex) { | |
System.out.println("Erreur mp3"); | |
} | |
} | |
}.start(); | |
} | |
public void stop() { | |
if (mp3Lecteur != null) { | |
mp3Lecteur.close(); | |
} | |
} | |
public void pause() { | |
if(mp3Lecteur != null){ | |
pos = mp3Lecteur.getPosition(); | |
new Thread() { | |
public void run() { | |
try { | |
mp3Lecteur.play(pos); | |
} catch (JavaLayerException ex) { | |
System.out.println("Erreur mp3"); | |
} | |
} | |
}.start(); | |
} | |
else{ | |
try { | |
play(); | |
} catch (JavaLayerException ex) { | |
Logger.getLogger(playerGUI.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} | |
} | |
/** | |
* This method is called from within the constructor to initialize the form. | |
* WARNING: Do NOT modify this code. The content of this method is always | |
* regenerated by the Form Editor. | |
*/ | |
@SuppressWarnings("unchecked") | |
// <editor-fold defaultstate="collapsed" desc="Generated Code"> | |
private void initComponents() { | |
playB = new javax.swing.JButton(); | |
stopB = new javax.swing.JButton(); | |
pauseB = new javax.swing.JButton(); | |
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); | |
playB.setText("Play"); | |
playB.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
playBActionPerformed(evt); | |
} | |
}); | |
stopB.setText("stop"); | |
stopB.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
stopBActionPerformed(evt); | |
} | |
}); | |
pauseB.setText("pause/play"); | |
pauseB.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
pauseBActionPerformed(evt); | |
} | |
}); | |
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); | |
getContentPane().setLayout(layout); | |
layout.setHorizontalGroup( | |
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(layout.createSequentialGroup() | |
.addGap(98, 98, 98) | |
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addComponent(pauseB) | |
.addGroup(layout.createSequentialGroup() | |
.addComponent(playB) | |
.addGap(18, 18, 18) | |
.addComponent(stopB))) | |
.addContainerGap(178, Short.MAX_VALUE)) | |
); | |
layout.setVerticalGroup( | |
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | |
.addGroup(layout.createSequentialGroup() | |
.addGap(107, 107, 107) | |
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) | |
.addComponent(playB) | |
.addComponent(stopB)) | |
.addGap(18, 18, 18) | |
.addComponent(pauseB) | |
.addContainerGap(129, Short.MAX_VALUE)) | |
); | |
pack(); | |
}// </editor-fold> | |
private void playBActionPerformed(java.awt.event.ActionEvent evt) { | |
try { | |
// TODO add your handling code here: | |
play(); | |
} catch (JavaLayerException ex) { | |
Logger.getLogger(playerGUI.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} | |
private void stopBActionPerformed(java.awt.event.ActionEvent evt) { | |
// TODO add your handling code here: | |
stop(); | |
} | |
private void pauseBActionPerformed(java.awt.event.ActionEvent evt) { | |
// TODO add your handling code here: | |
pause(); | |
} | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String args[]) { | |
/* Set the Nimbus look and feel */ | |
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> | |
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. | |
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html | |
*/ | |
try { | |
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { | |
if ("Nimbus".equals(info.getName())) { | |
javax.swing.UIManager.setLookAndFeel(info.getClassName()); | |
break; | |
} | |
} | |
} catch (ClassNotFoundException ex) { | |
java.util.logging.Logger.getLogger(playerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (InstantiationException ex) { | |
java.util.logging.Logger.getLogger(playerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (IllegalAccessException ex) { | |
java.util.logging.Logger.getLogger(playerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (javax.swing.UnsupportedLookAndFeelException ex) { | |
java.util.logging.Logger.getLogger(playerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} | |
//</editor-fold> | |
/* Create and display the form */ | |
java.awt.EventQueue.invokeLater(new Runnable() { | |
public void run() { | |
new playerGUI().setVisible(true); | |
} | |
}); | |
} | |
// Variables declaration - do not modify | |
private javax.swing.JButton pauseB; | |
private javax.swing.JButton playB; | |
private javax.swing.JButton stopB; | |
// End of variables declaration | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment