Mp3 java

Fermé
Hacker#1 Messages postés 76 Date d'inscription mardi 6 janvier 2009 Statut Membre Dernière intervention 20 avril 2010 - 25 oct. 2009 à 11:17
choubaka Messages postés 39375 Date d'inscription jeudi 4 avril 2002 Statut Modérateur Dernière intervention 14 avril 2024 - 25 oct. 2009 à 17:33
Bonjour,
je veux integer la classe jlp de JLayer1.0.1 avec mon interface graphique qui peut afficher le nom de mp3
dans la zone de text ,deux boutons un bouton play et stop et une commande jslider pour changer le volume
lorqu'on clique sur le bouton play je veux qu'il change pause
lorsqu'on clique sur pause on fait une pause sur mp3
aider moi svp
NewJFrame
package mm;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class NewJFrame  {
	 
  
    	public static void main(String[] args)throws Exception{
    		 JFrame f = new JFrame();
    		 Ecouteur ec = new Ecouteur();
    		 
    		 f.setSize(300, 250);
     
    		 f.setTitle("mp3 player");  

    		        JButton jButton1 = new JButton();
    		        JButton jButton2 = new JButton();
    		        JSlider jSlider1 = new JSlider();
    		        JTextField jTextField1 = new JTextField();

    		        jButton1.addActionListener(ec);
    		        jButton2.addActionListener(ec);
    		        //jSlider1.addMouseListener((MouseListener) ec);
    		        jTextField1.addActionListener(ec);
    		        
    		        jButton1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
    		        jButton1.setText("play");
    		       
    		        jButton2.setFont(new java.awt.Font("Tahoma", 0, 14));
    		        jButton2.setText("stop");
    		       
    		        jTextField1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
    		      
    		        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(f.getContentPane());
    		        f.getContentPane().setLayout(layout);
    		        layout.setHorizontalGroup(
    		            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    		            .addGroup(layout.createSequentialGroup()
    		                .addGap(44, 44, 44)
    		                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
    		                    .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    		                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
    		                        .addComponent(jTextField1)
    		                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
    		                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
    		                            .addGap(30, 30, 30)
    		                            .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))))
    		                .addContainerGap(50, Short.MAX_VALUE))
    		        );
    		        layout.setVerticalGroup(
    		            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    		            .addGroup(layout.createSequentialGroup()
    		                .addContainerGap()
    		                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
    		                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
    		                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    		                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
    		                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE))
    		                .addGap(33, 33, 33)
    		                .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    		                .addContainerGap(48, Short.MAX_VALUE))
    		        );
	    
        f.setResizable(false);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
        
    }
}
    	class Ecouteur implements ActionListener{	
    public void actionPerformed(ActionEvent e){
    	jlp j=new jlp();
    if(e.getActionCommand().equals("play")) 
	{ 
    	j.chemin();
	
	} 
    }
   
}

jlp
package mm;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.AudioDevice;
import javazoom.jl.player.FactoryRegistry;
import javazoom.jl.player.Player;

public class jlp
{
	private String fFilename = null;
	private boolean remote = false;

	   void chemin()
		{int retval = 0;
		try
		{   String[] s={"C:/Clocksmp3"};
			jlp player = createInstance(s);
			if (player!=null)
				player.play();
		}
		catch (Exception ex)
		{
			System.err.println(ex);
			ex.printStackTrace(System.err);
			retval = 1;
		}
		System.exit(retval);
		}
		
	static public jlp createInstance(String[] args)
	{
		jlp player = new jlp();
		if (!player.parseArgs(args))
			player = null;
		return player;
	}

	jlp()
	{
	}

	public jlp(String filename)
	{
		init(filename);
	}

	protected void init(String filename)
	{
		fFilename = filename;
	}

	protected boolean parseArgs(String[] args)
	{
		boolean parsed = false;
		if (args.length == 1)
		{
			init(args[0]);
			parsed = true;
			remote = false;
		}
		else if (args.length == 2)
		{
			if (!(args[0].equals("-url")))
			{
				showUsage();
			}
			else
			{
				init(args[1]);
				parsed = true;
				remote = true;
			}
		}
		else
		{
			showUsage();
		}
		return parsed;
	}

	public void showUsage()
	{
		System.out.println("Usage: jlp [-url] <filename>");
		System.out.println("");
		System.out.println(" e.g. : java javazoom.jl.player.jlp localfile.mp3");
			}
	public void stop()
	throws JavaLayerException
{
	try
	{
		
		InputStream in = null;
		if (remote == true)
			try {
				in = getURLInputStream();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		else in = getInputStream();
		AudioDevice dev = getAudioDevice();
		Player player = new Player(in, dev);
		player.close();
	}
	catch (IOException ex)	{}
	
}
	public void play()
		throws JavaLayerException
	{
		try
		{
			System.out.println("playing "+fFilename+"...");
			InputStream in = null;
			if (remote == true) in = getURLInputStream();
			else in = getInputStream();
			AudioDevice dev = getAudioDevice();
			Player player = new Player(in, dev);
			player.play();
		}
		catch (IOException ex)
		{
			throw new JavaLayerException("Problem playing file "+fFilename, ex);
		}
		catch (Exception ex)
		{
			throw new JavaLayerException("Problem playing file "+fFilename, ex);
		}
	}

	/**
	 * Playing file from URL (Streaming).
	 */
	protected InputStream getURLInputStream()
		throws Exception
	{

		URL url = new URL(fFilename);
		InputStream fin = url.openStream();
		BufferedInputStream bin = new BufferedInputStream(fin);
		return bin;
	}

	/**
	 * Playing file from FileInputStream.
	 */
	protected InputStream getInputStream()
		throws IOException
	{
		FileInputStream fin = new FileInputStream(fFilename);
		BufferedInputStream bin = new BufferedInputStream(fin);
		return bin;
	}

	protected AudioDevice getAudioDevice()
		throws JavaLayerException
	{
		return FactoryRegistry.systemRegistry().createAudioDevice();
	}

}

1 réponse

choubaka Messages postés 39375 Date d'inscription jeudi 4 avril 2002 Statut Modérateur Dernière intervention 14 avril 2024 2 100
25 oct. 2009 à 17:33
salut

nullepart dans ta classe maij, je ne vois la déclaration de ta classe jlp
-1