外部ストレージは機能しますが、内部ストレージは機能しません。Android ストレージ メカニズムから根本的に何かを見逃していますか?
ありがとう
public static void playSound()
{
//String path = internalPath + "/www/sounds/" + "SIREN.WAV"; // doesnt work
//String path = "file:///data/data/com.myproject.d08062014f/files/www/sounds/SIREN.WAV"; // doesnt work
//String path = "/data/data/com.myproject.d08062014f/files/www/sounds/SIREN.WAV"; // doesnt work
// all above does not work
Log.d("command", "command:" + path); // to check path string
String path = "file:///mnt/sdcard/media/audio/notifications/facebook_ringtone_pop.m4a"; // This one works!
MediaPlayer mMediaPlayer = new MediaPlayer();
try {
mMediaPlayer.setDataSource(path);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mMediaPlayer.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mMediaPlayer.start();
}
2014 年 9 月 10 日の更新
stackoverflow.com/a/4955915/856007 – Abdullah Shoaib 8 月 12 日 7:49 に、以下の参照リンクをありがとう、私はそれを動作させることができました
File file = new File(path); // acquire the file from path string
FileInputStream inputStream = new FileInputStream(file);
mMediaPlayer.setDataSource(inputStream.getFD());
inputStream.close();