寫了一個音樂播放器,播放的時候,會出現這樣的問題:比如說我點擊第三首歌曲,結果沒有播放第三首歌曲,而直接播放了第四首歌曲。看了一下日志。發現報錯:MediaPlayer: Couldn't open /storage/emulated/0/kgmusic/download/陳小春 - 獨家記憶.mp3: java.io.FileNotFoundException: No content provider: /storage/emulated/0/kgmusic/download/陳小春 - 獨家記憶.mp3
詳見截圖:

大家也可以搜一下MediaPlayer:error(-38,0)這個錯誤。
英語好的可以看一下這個鏈接。
截圖給大家看看:

紅框里的英文大家可以仔細看一下:說的是MediaPlayer - java.io.FileNotFoundException: No content provider這個bug可能會發生在安卓7.0(牛軋糖)或者更高的版本上。如果你把你的app運行在安卓7.0(牛軋糖)或者更高版本的安卓系統上,你最好使用Content Provider。
PS:我的app運行在了7.0的手機上,而且我也沒用Content Provider。所以導致了這個問題。
我的音樂播放器的module的build.gradle如下圖所示,最低版本是11,目標版本是22,編譯版本是23,把這個音樂播放器運行到安卓7.0的小米手機上時,就會出現上面的bug。

|
This issue occurs in Nougat or higher version if you are using nougat or higher version you have to use Create an XML file (for example file_provider_paths.xml) in XML resources folder:
Now define a provider in your ApplicationManifest.xml, add this provider inside application node:
Now get the shared file URI, and use it in your application where you need it.
|
