MediaPlayer cant play audio files from program data folder?

后端 未结 5 1749
春和景丽
春和景丽 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 19:01

    i had the same issues... whenever i used setDataSource with filepaths, it would not work; kept getting IOException.

    changing my code to use setDataSource(FileDescriptor) does work... and with this i don't have to copy the files to SDCard or anything like that.

    So, with a simple File object, create a new FileInputStream and pass the actual file descriptor as data source as in:

    setDataSource((new FileInputStream(myFileInstance)).getFD());
    

    creating an input stream pulls the file data into memory and thereby addresses /data/data access violations.

提交回复
热议问题