2009-01-23 163 views
5

播放使用J2ME Media庫的音頻的最佳方式是什麼? 例如,我應該使用MMAPI還是應該使用Midlet的platformRequest(String s)方法?使用J2ME播放音頻

+0

這實際上取決於你想要做什麼......你應該更具體地對待你所追求的。如果你想播放MP3,這很容易。如果你想通過互聯網傳輸音頻,幾乎不可能。 – joeforker 2009-01-23 17:50:19

回答

3

通過最好,你是什麼意思?最好的質量?最佳的用戶體驗?大多數標準兼容?基本上(這不是我所知道的最好的答案),它取決於平臺 - 這是J2ME熟悉的主題 - 因爲實現可能差異很大,MMAPI通常利用一些本地媒體播放器軟件/硬件。在黑莓手機上,MMAPI效果很好,有一些怪癖。

我的建議是使用MMAPI,它工作得很好 - 它會給你最便攜的應用程序。試驗或瀏覽您的特定目標設備組的開發板,以瞭解它在您想要支持的手機上的功能。

7

以下代碼適用於那些支持JSR-135的手機的90-95%。對所有各種方法調用進行排序是便攜式的關鍵。這適用於JAR本地的聲音。任何流音頻將是另一個問題完全:)

// loads the InputStream for the sound 
InputStream inputStream = this.getClass().getResourceAsStream(musicFile); 

// create the standard Player 
musicPlayer = Manager.createPlayer(inputStream, musicEncoding); 
musicPlayer.prefetch(); 

// add player listener to access sound events 
musicPlayer.addPlayerListener(this); 

if(loopMusic) 
{  
    // use the loop count method for infinite looping 
    musicPlayer.setLoopCount(-1); 
} 

// The set occurs twice to prevent sound spikes at the very 
// beginning of the sound. 
VolumeControl volumeControl = 
    (VolumeControl) musicPlayer.getControl("VolumeControl"); 
volumeControl.setLevel(curVolume); 

// finally start the piece of music 
musicPlayer.start(); 

// set the volume once more 
volumeControl = (VolumeControl) musicPlayer.getControl("VolumeControl"); 
volumeControl.setLevel(curVolume); 

// finally, delete the input stream to save on resources 
inputStream.close(); 
inputStream = null; 
0

使用的平臺要求某些設備會導致應用程序關閉,並對其他特定平臺的請求將崩潰裝置(以外的任何其他HTTP網址,在某些設備上) 。

因此,您可能需要使用兩種方法,根據設備測試選擇使用哪一種方法。

-1

如上面Shane的回覆中所解釋的,本地音頻(在Jar文件中)更容易支持。對於網絡上的內容來說,由於諸如服務器連接問題,手機內存等諸多因素的影響,這變得更加困難。如果您需要支持大量手機,那麼建議您使用2-3種實現技術並相應使用。