MediaPlayer.setDataSource(String) not working with local files

前端 未结 6 1045
一个人的身影
一个人的身影 2020-12-02 20:31

I am able to play a local mp3 if I use the static method MediaPlayer.create(context, id) but it\'s not working if I use the non-static method MediaPlayer.setDataSource(Strin

6条回答
  •  囚心锁ツ
    2020-12-02 21:15

    You have to use setDataSource(@NonNull Context context, @NonNull Uri uri) instead of setDataSource(String path)

    Since you want to resolve resource internal application resources, you have to provide Context which would be used to resolve this stuff

    Also if you will take a look inside these two methods you will notice they use different strategies to find resulting resource.

提交回复
热议问题