我想使用Uri
播放一首歌。我正在使用媒体播放器播放这首歌,但我收到了IOException。
try{
String url = "http://stream6.infotraxsys.com/conference/archive/5064/84727/local-6";
final MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
return false;
}
});
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mediaPlayer.start();
}
});
mediaPlayer.setDataSource(MainActivity.this,Uri.parse("http://stream6.infotraxsys.com/conference/archive/5064/84727/local-6"));
mediaPlayer.prepareAsync();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//I got this exception
3-18 17:11:15.947 16703-16703/com.example.XXXXXXX.playsong V/MediaPlayer-JNI﹕ native_setup
03-18 17:11:15.947 16703-16703/com.example.XXXXXXX.playsong V/MediaPlayer﹕ constructor
03-18 17:11:15.947 16703-16703/com.example.XXXXXXX.playsong V/MediaPlayer﹕ setListener
03-18 17:11:16.502 16703-16703/com.example.XXXXXXX.playsong V/MediaPlayer-JNI﹕ setAudioStreamType: 3
03-18 17:11:16.502 16703-16703/com.example.XXXXXXX.playsong V/MediaPlayer﹕ MediaPlayer::setAudioStreamType
03-18 17:11:18.447 16703-16703/com.example.XXXXXXX.playsong I/MediaPlayer﹕ path is null
03-18 17:11:18.452 16703-16703/com.example.XXXXXXX.playsong D/MediaPlayer﹕ Couldn't open file on client side, trying server side
03-18 17:11:18.462 16703-16703/com.example.XXXXXXX.playsong E/MediaPlayer﹕ Unable to to create media player
03-18 17:11:26.432 16703-16703/com.example.XXXXXXX.playsong W/System.err﹕ java.io.IOException: setDataSource failed.: status=0x80000000
03-18 17:11:26.437 16703-16703/com.example.XXXXXXX.playsong W/System.err﹕ at android.media.MediaPlayer._setDataSource(Native Method)
03-18 17:11:26.442 16703-16703/com.example.XXXXXXX.playsong W/System.err﹕ at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1160)
03-18 17:11:26.452 16703-16703/com.example.XXXXXXX.playsong W/System.err﹕ at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1131)
03-18 17:11:26.452 16703-16703/com.example.XXXXXXX.playsong W/System.err﹕ at android.media.MediaPlayer.setDataSource(MediaPlayer.java:964)
03-18 17:11:26.457 16703-16703/com.example.XXXXXXX.playsong W/System.err﹕ at android.media.MediaPlayer.setDataSource(MediaPlayer.java:895)
03-18 17:11:26.462 16703-16703/com.example.XXXXXXX.playsong W/System.err﹕ at com.example.XXXXXXX.playsong.MainActivity.onClick(MainActivity.java:105)
03-18 17:11:26.467 16703-16703/com.example.XXXXXXX.playsong W/System.err﹕ at android.view.View.performClick(View.java:4261)
03-18 17:11:26.472 16703-16703/com.example.XXXXXXX.playsong W/System.err﹕ at android.view.View$PerformClick.run(View.java:17356)
03-18 17:11:26.477 16703-16703/com.example.XXXXXXX.playsong W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:615)
03-18 17:11:26.482 16703-16703/com.example.XXXXXXX.playsong W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:92)
03-18 17:11:26.487 16703-16703/com.example.XXXXXXX.playsong W/System.err﹕ at android.os.Looper.loop(Looper.java:137)
03-18 17:11:26.492 16703-16703/com.example.XXXXXXX.playsong W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:4921)
03-18 17:11:26.497 16703-16703/com.example.XXXXXXX.playsong W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
03-18 17:11:26.507 16703-16703/com.example.XXXXXXX.playsong W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:511)
03-18 17:11:26.507 16703-16703/com.example.XXXXXXX.playsong W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
03-18 17:11:26.512 16703-16703/com.example.XXXXXXX.playsong W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
03-18 17:11:26.517 16703-16703/com.example.XXXXXXX.playsong W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)
03-18 17:13:10.892 16703-16703/com.example.XXXXXXX.playsong W/IInputConnectionWrapper﹕ getSelectedText on inactive InputConnection
03-18 17:13:10.892 16703-16703/com.example.XXXXXXX.playsong W/IInputConnectionWrapper﹕ setComposingText on inactive InputConnection