簡體   English   中英

在Android中播放sdcard0發出的聲音

[英]Play a sound from sdcard0 in android

MediaPlayer mp;
mp = MediaPlayer.create(this, R.drawable.test);
mp.start();

那是我的代碼。 它只是從res / drawable /文件夾播放聲音。 我需要從android的sdcard0 / Test Folder / testsound.amr播放聲音。

請幫忙。 提前致謝。

只需使用setDataSource方法:

MediaPlayer mp = new MediaPlayer();
//set the source of the Sound...
mp.setDataSource("/mnt/sdcard/Test Folder/testsound.amr");
//load the file
mp.prepare(); 
//Do the thing (:
mp.start();

您還可以通過以下方式動態地執行此操作:

mp.setDataSource(Environment.getExternalStorageDirectory().getPath()+"/Test Folder/testsound.amr");

注意:我不確定您是否需要執行.getPath()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM