MediaPlayer cant play audio files from program data folder?

后端 未结 5 1808
春和景丽
春和景丽 2021-02-15 18:11

When i record my audio from MIC and store file in /data/data/..... why MediaPlayer can\'t play this file ? If i change destination to / sdcard/..... - all works great. I do so

5条回答
  •  没有蜡笔的小新
    2021-02-15 18:58

    Due to the Android security model, MediaPlayer haven't enough rights. It can access SD card, but can't access another places with out permissions.

    As so, setDataSource(...) can thrown SecurityException and I think it's happening.

    You can play this file next ways:

    • copy it to temp dir and play;
    • copy it to temp dir and play;
    • copy it to sdcard;
    • read it fully to memory and try play via stream.

提交回复
热议问题