简体   繁体   中英

I can not use JMF

在此输入图像描述 Now 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);
} 
 }

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.

Try using this:

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

works good for me..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM