这是我应该播放记录文件的playButton。
playButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String main_path = c.getFilesDir().getPath();
String appended_path = main_path+"/recordings";
String newSource = appended_path+"/"+source;
Log.e("Source File", newSource);
String fixedUrl = newSource.replaceAll("\\s", "%20");
playFile(fixedUrl);
}
});
文件名具有这样的特殊字符(空格)。我如上面的fixedUrl(String)所示逃脱了它。 但是,它不能很好地工作。假设名为“ record.3gp”的文件播放顺畅,而名为“ 2018:11:06 18:16:12.3gp”的文件无法播放,因为它说:
Failed to open file '/data/user/0/com.utilnepal/files/recordings/2018:11:06%2018:12:53.3gp'. (Permission denied)
任何想法如何解决这个问题? 这是播放方法
private void playFile(String source, final RecordingViewHolder recordingViewHolder) {
// getPermission();
mPlayer = new MediaPlayer();
try {
mPlayer.setDataSource(source);
mPlayer.prepare();
mPlayer.start();
//
} catch (IOException e) {
Log.e("Error Occured", "prepare() failed " +e.getMessage());
Toast.makeText(c,"Cannot Play File",Toast.LENGTH_LONG).show();
togglePause(recordingViewHolder);
}
}