0

enter image description hereNow I am trying with another sound file with mp3 codec. But I am encounterring problem to start the player.

I have downloaded the file from http://www.mediacollege.com/audio/tone/download/

The output from Netbeans is:

run: Error: Unable to realize com.sun.media.amovie.AMController@ebf3f0 BUILD SUCCESSFUL (total time: 2 seconds)

And my program is:

import javax.media.*;
import java.io.*;
public class MP3Player {
public static void main(String[] args) throws Exception 
{    
File file = new File("c:/player/sound.mp3");    
MediaLocator mrl = new MediaLocator(file.toURL());    
Player player = Manager.createPlayer(mrl);    
player.start(); 
Thread.sleep(1000);
} 
 }
Alex
  • 75
  • 1
  • 9

2 Answers2

2

JMF does not support the mp3 format due to licensing issues.

This article on extending JavaSound to Play MP3 should give you everything that you need, including a place to download an mp3 codec. I have recently used this sample code as the basis for an mp3 player, and used it on both Windows and OS X, and I can verify that it works very well.

GreyBeardedGeek
  • 29,460
  • 2
  • 47
  • 67
0

Try using this:

String theFile = "file:///c:/player/sound.mp3";
MediaLocator mrl = new MediaLocator(theFile); 

works good for me..

hanx
  • 83
  • 1
  • 3