1

in this code i select mp3 path is "D:/camera.wav". when i make jar file of this code, it play in only my system. please tell me how to add camera.wav file to my project and give that url to my project. because i want same music should play for all systems, even though they don't have that music.

import java.io.File; 
import javax.media.Format; 
import javax.media.Manager; 
import javax.media.MediaLocator; 
import javax.media.Player; 
import javax.media.PlugInManager; 
import javax.media.format.AudioFormat; 
public class maintest 
{ 
    public static void main(String[] args) 
    { 
    //float v=1; 
    Format input1 = new AudioFormat(AudioFormat.MPEGLAYER3); 
    Format input2 = new AudioFormat(AudioFormat.MPEG); 
    Format output = new AudioFormat(AudioFormat.LINEAR); 
    PlugInManager.addPlugIn("com.sun.media.codec.audio.mp3.JavaDecoder", 
        new Format[]{input1, input2}, 
        new Format[]{output}, 
        PlugInManager.CODEC ); 
    try 
    { 
        Player player = Manager.createPlayer(new MediaLocator(new       File("D:/camera.wav").toURI().toURL())); 
        //player.getGainControl().setLevel(v); 
        player.start(); 
    } 
    catch(Exception ex){ 
        ex.printStackTrace(); 
    } 
} 
}
user2158386
  • 25
  • 1
  • 2
  • 6
  • AFAIK JMF has limited or no support for MP3. You might like to take a look at [JavaZoom's JLayer API](http://www.javazoom.net/javalayer/javalayer.html) – MadProgrammer Sep 05 '13 at 07:15
  • Visit http://stackoverflow.com/questions/5667454/playing-mp3-using-java-sound-api even i had same issue – Developer Desk Sep 05 '13 at 07:17
  • Did you beside adding jars to eclipse install JMF 2.1.1e to your system and restart your computer? – Pshemo Sep 05 '13 at 08:29
  • @MadProgrammer JMF includes an SPI for decoding MP3 that works with most MP3 files (including VBR). The only ones it seems to fail on is malformed MP3s (that can typically still be played by more robust players). – Andrew Thompson Sep 05 '13 at 08:51
  • @AndrewThompson I have it my head that it doesn't support all formats of mp3, might be mp4, but, technically it doesn't support mp3, without plugin ;) but that's nit picks – MadProgrammer Sep 05 '13 at 09:21
  • @MadProgrammer , in this code i select mp3 path is "D:/camera.wav". when i make jar file of this code, it play in only my system. please tell me how to add camera.wav file to my project and give that url to my project – user2158386 Sep 06 '13 at 07:34
  • @Pshemo, nope. don't try to import package before add plugin. once u get successfully integrate your plugin to eclipse, then import the package and do your coding. – user2158386 Sep 06 '13 at 09:21

3 Answers3

1

JMF is .. ancient. it hasn't been maintained/updated for years, so especially if you want to have some "modern" code, JMF is not the best option.

personally, I once created (al be it a simple one) a small mp3 player, using the JLayer library which you can find here it has plenty of documentation and examples so it shouldn't take too long to get you going.

Stultuske
  • 9,296
  • 1
  • 25
  • 37
0

You need the MP3 Plugin. Or if that doesn't work, this plugin is also a good resource.

William Gaul
  • 3,181
  • 2
  • 15
  • 21
  • which is the mp3? J A I API 1.1.2_01 J A I API Demo 1.1.2 J A I 1.1.1_01 J A I API Documentation 1.1 Maintenance Release J A I API Tutorial 1.1 J A I Guide 1.0.1 J A I Image I/O Tools 1.0_01 J A I Image I/O Tools Documentation 1.0_01 J A I ICC Profiles J 3D 1.5.1 J 3D API 1.4.0_01 J 3D Implementation Documentation 1.4.0_01 JMF 2.1.1e J Access Bridge for Windows Operating System 2.0.1 J Web Start Sample Applications 1.2 J Look and Feel Graphics Repository 1.0 J L & F Design Guide second edition J Internationalization and Localization Toolkit 2.0 J Accessibility Utilities 1.3 JIMI SDK – user2158386 Sep 05 '13 at 07:50
  • See [this answer](http://stackoverflow.com/a/8392893/418556) for a source on the `mp3plugin.jar`. Note that with it on the run-time class-path, an MP3 can be played using Java Sound - no requirement for the rest of the JMF. – Andrew Thompson Sep 05 '13 at 09:24
  • @AndrewThompson, in this code i select mp3 path is "D:/camera.wav". when i make jar file of this code, it play in only my system. please tell me how to add camera.wav file to my project and give that url to my project. – user2158386 Sep 06 '13 at 07:33
  • I don't use Eclipse that much. – Andrew Thompson Sep 06 '13 at 07:53
0

You can also use JavaFX for playing MP3's. If you use Netbeans just create a new project and select JavaFX project instaed of a normal Java project

Kelevra
  • 95
  • 10