开发者

Playing Audio file

开发者 https://www.devze.com 2023-03-03 04:01 出处:网络
I use the following code to play audio from sdcard. But it doesn\'t play, even doesn\'t throw error. My file is in the following path /sdcard/media/blueeye.mp3. Any suggestions.

I use the following code to play audio from sdcard. But it doesn't play, even doesn't throw error. My file is in the following path /sdcard/media/blueeye.mp3. Any suggestions.

public void audioPlayer(){
    //set up MediaPlayer    
    MediaPlayer mp = new MediaPlayer();

    try {
        mp.setDataSource(mp.setDataSource(getExternalFilesDir() + "/media/blueeye.mp3"); );
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        mp.prepare();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-g开发者_开发问答enerated catch block
        e.printStackTrace();
    }
    mp.start();
}


I think it should be /mnt/sdcard/media/blueeye.mp3 and please use getExternalFilesDir():

mp.setDataSource(getExternalFilesDir() + "/media/blueeye.mp3"); 

Also, If you'd set your own onErrorListener, you will be able to see easily what the problem is.

0

精彩评论

暂无评论...
验证码 换一张
取 消