Player..(ajudem)

esse é o programa…
deem uma olhada…

[b]package jplayer;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JPanel;

import java.io.;
import java.awt.
;
import java.awt.event.;
[b]import javax.swing.
;
import javax.sound.midi.*;

public class JPlayer extends JFrame {

 private JTextField jtCaminho = new JTextField(15);


 private JButton jbSetCam = new JButton("Abrir");


 private JButton jbPlay = new JButton("play/pause");


 private JLabel lblInfo = new JLabel("info: ");


 private boolean play = true;

 public JPlayer(){
            super("JPlayer");
            Container c = getContentPane();
            c.setLayout( new FlowLayout() );
            c.add( new JLabel("Caminho: ") );
            c.add( jtCaminho );

            jbSetCam.addActionListener ( new ActionListener() {
                       public void actionPerformed ( ActionEvent e ){
                 Abrir() ;
                 }  } ) ;
            c.add( jbSetCam );

            jbPlay.addActionListener ( new ActionListener() {
                       public void actionPerformed ( ActionEvent e ){
                 plays( jtCaminho.getText() ) ;
                 }  } ) ;
            c.add( jbPlay );
            c.add( lblInfo );
            setVisible( true );
            setDefaultCloseOperation( EXIT_ON_CLOSE );
            setSize( 300, 100 );
    try {
        jbInit();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
         public void plays(String caminho ){
                      try {
                         Sequence sequence = MidiSystem.getSequence( new File(caminho) );
                             Sequencer sequencer = MidiSystem.getSequencer();
                         sequencer.open();

                         if ( play ){

                         sequencer.setSequence( sequence );
                         sequencer.start();
                          //mostra o tempo total do arquivo MIDI em microsegundos.
                         lblInfo.setText( "Info: " + sequencer.getMicrosecondLength() + "   MSegs" );
                         play = false ;
                          } else {
                         sequencer.stop(); //pausa o dispositivo.
                         play = true ;
                         }

                      }catch( Exception e ){
                       System.out.println( e.toString() );
                      }
     }
     public void Abrir() {
             JFileChooser escolha = new JFileChooser();
             escolha.setFileSelectionMode( JFileChooser.FILES_ONLY );
             escolha.showOpenDialog(this);
             jtCaminho.setText( escolha.getSelectedFile().toString() );
     }



             public static void main( String[] args ){
             JPlayer jp = new JPlayer();
              jp.show();
             }

private void jbInit() throws Exception {
}

}[/b]

o erro que aparece é esse…

javax.sound.midi.InvalidMidiDataException: could not get sequence from file

a esqueci de dize…

é que ele ñ toca a musica

hehehe

fois mal

Tem certeza que é um mid válido?

PS: Ao postar código, formata com a tag code… Se não sabe fazer isso, leia esse tutorial aqui.

cara, testei teu codigo aqui e ta funcionando sem problema.
sera q vc nao ta tentando abrir outro tipo de arquivo? mp3 por ex?

então pra que tipo de extensão de musica é…
ja tentei wav e mp3 e esses ñ deu…

o que se precisa pra rodar um arquivo mp3???

vlw

Ë para arquivos .mid.

Para MP3 e OGG, dê uma olhada na biblioteca:
http://www.javazoom.net/

Existem também classes que rodam som wav nativos do Java. Procure por AudioClip ou, se quiser algo mais avançado, pela classe DataLine e o método AudioSystem.getLine().

como eu faço pra implantar o javazoom no Jbuilder…

tem uma função pra importar “lib”, é por ali???

porque ainda ñ está tocando nenhum tipo de arquivo…

vlw

No JBuilder não sei. Mas deve ser por ali mesmo.

Não pense que vai ser só importar o javazoom e seu código irá sair tocando MP3. O Sequencer é uma classe específica para arquivos mid. Você terá que entrar no site do javazoom e ver os exemplos de como usa-lo.