Simple mediaplayer play mp3 from file path?

前端 未结 6 616
执笔经年
执笔经年 2020-11-28 11:40

I have a very simple mediaplayer that play background. It calls file from the apk, but I want it to play from any directory like as music or sdcard.

Here are my code

6条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 12:15

    Use the code below it worked for me.

    MediaPlayer mp = new MediaPlayer();
    mp.setDataSource("/mnt/sdcard/yourdirectory/youraudiofile.mp3");
    mp.prepare();
    mp.start();
    

提交回复
热议问题