Android MediaPlayer正在从localhost加载文件,但不是从在线服务器加载。
Android开发者指南
String url = "http://10.0.2.2/music.mp3"; // this works
String url = "http://example.com/audios/music.mp3"; // this does not works
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(url);
mediaPlayer.prepare();
mediaPlayer.start();
日志显示:
05-28 20:31:20.403 942-2444/? E/NuCachedSource2: source returned error -1, 10 retries left
05-28 20:31:24.308 942-2444/? E/NuCachedSource2: source returned error -1, 9 retries left
05-28 20:31:28.231 942-2444/? E/NuCachedSource2: source returned error -1, 8 retries left
05-28 20:31:32.150 942-2444/? E/NuCachedSource2: source returned error -1, 7 retries left
05-28 20:31:36.061 942-2444/? E/NuCachedSource2: source returned error -1, 6 retries left
05-28 20:31:39.974 942-2444/? E/NuCachedSource2: source returned error -1, 5 retries left
05-28 20:31:43.937 942-2444/? E/NuCachedSource2: source returned error -1, 4 retries left
05-28 20:31:47.858 942-2444/? E/NuCachedSource2: source returned error -1, 3 retries left
05-28 20:31:51.798 942-2444/? E/NuCachedSource2: source returned error -1, 2 retries left
05-28 20:31:55.740 942-2444/? E/NuCachedSource2: source returned error -1, 1 retries left
05-28 20:32:00.258 2405-2405/? W/System.err: java.io.IOException: Prepare failed.: status=0x1
然后是ANR错误。
请帮忙。 Thanx提前!