使用android stutio做音乐播放器demo时,读取sd卡上的音频文件读取不到,报下边的错误:
FileNotFoundException: /storage/emulated/0/music.mp3: open failed: EACCES (Permission denied)
点击播放按钮报错:
2020-07-13 11:09:39.400 26419-26419/com.example.musicdemo E/MediaPlayerNative: start called in state 1, mPlayer(0x0)
2020-07-13 11:09:39.400 26419-26419/com.example.musicdemo E/MediaPlayerNative: error (-38, 0)
2020-07-13 11:09:39.406 26419-26419/com.example.musicdemo E/MediaPlayer: Error (-38,0)
解决方案:
在AndroidManifest.xml中的application标签下添加属性:
android:requestLegacyExternalStorage="true"