Simple mediaplayer play mp3 from file path?

前端 未结 6 615
执笔经年
执笔经年 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:18

    Here is the code to set up a MediaPlayer to play off of the SD card:

    String PATH_TO_FILE = "/sdcard/music.mp3";    
    mediaPlayer = new  MediaPlayer();
    mediaPlayer.setDataSource(PATH_TO_FILE);
    mediaPlayer.prepare();   
    mediaPlayer.start()
    

    You can see the full example here. Let me know if you have any problems.

提交回复
热议问题