2011-08-02 66 views
1

我需要使用Android SDK播放長音頻文件。我知道Android提供的MediaPlayer框架,但我想知道內置的「音樂播放器」應用程序可以被調用,所以我不必編寫自己的播放器GUI和代碼。在Android中播放音頻文件

回答

4

是的,你可以。
建立一個意圖是這樣的:

act=android.intent.action.VIEW dat=file:///mnt/sdcard/song_name.mp3 typ=audio/mpeg3 

操作:VIEW

 
Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(Uri 
       .parse("file:///mnt/sdcard/song_name.mp3"), 
       "audio/mpeg3"); 
startActivity(intent); 
+1

的'correct'方式(或者在道路也許不太皺起了眉頭)訪問SD卡使用環境' .getExternalStorageDirectory()'。這會將您的文件字符串更改爲'Uri.parse(「file:///」+ Environment.getExternalStorageDirectory()。getAbsolutePath()+「/song_name.mp3」)' – Phil

+0

是的。謝謝@Phil。我錯過了。 –