2017-05-24 6 views
0

JMFを使用してJavaでMP3ファイルを再生しようとするとエラーが発生します。私はWAVファイルで試して、うまくいきます。JMFでJavaでMP3を再生しようとするとフォーマットエラーが発生する

import javax.media.*; 
import java.net.URL; 

class mp3 extends Thread { 
    private URL url; 
    private Player playMP3; 

    public mp3(String mp3) { 
     try { 
      this.url = new URL(mp3); 
     } catch (java.net.MalformedURLException e) { 
      System.out.println(e.getMessage()); 
     } 
    } 

    public void run() { 

     try { 
      MediaLocator mediaLocator = new MediaLocator(url); 
      playMP3 = Manager.createPlayer(mediaLocator); 
     } catch (java.io.IOException | NoPlayerException e) { 
      System.out.println(e.getMessage()); 
     } 

     playMP3.addControllerListener(new ControllerListener() { 
      public void controllerUpdate(ControllerEvent e) { 
       if (e instanceof EndOfMediaEvent) { 
        playMP3.stop(); 
        playMP3.close(); 
       } 
      } 
     }); 
     playMP3.realize(); 
     playMP3.start(); 
    } 
} 

public class PlayMP3 { 
    public static void main(String[] args) { 
     mp3 t = new mp3("file:///C://TestMP3Player//music.wav"); // Works well 
//  mp3 t = new mp3("file:///C://TestMP3Player//music.mp3"); // Doesn't work (error below) 
     t.start(); 
     System.out.println("Playing song..."); 
    } 
} 

とエラー(this postと同じ)::私が正しくJMFをインストールした場合、私は知らない

Playing song... Unable to handle format: mpeglayer3, 44100.0 Hz, 16-bit, Stereo, LittleEndian, Signed, 16000.0 frame rate, FrameSize=32768 bits Failed to realize: [email protected] Error: Unable to realize [email protected]

Process finished with exit code 0

は、ここに私の(this tutorialに基づいて)コードです。

IntelliJ project dependancies window

この間違いを作るかのアイデア:私はちょうどこのようIntelliJのプロジェクトの依存関係にあるJARファイルが含まれているJMF-2.1.1e\libディレクトリを追加しますか?

ありがとうございました!

答えて

0

MP3ファイルがJMFで処理できない形式になっているようです。 幸いにも私はMP3ファイルを再生できるオーディオライブラリを持っています。

https://github.com/RalleYTN/SimpleAudio

関連する問題