我有这个在互联网上播放广播流的代码,这个代码像:-
package com.example.kam;
import java.io.IOException;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.media.AudioManager;
import android.media.MediaPlayer;
public class MainActivity extends Activity {
public MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
protected void onResume (){
super.onResume();
mp = new MediaPlayer();
try {
mp.setDataSource("http://radio.arabhosters.com:8015/");
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException 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();
}
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} //also consider mp.prepareAsync().
mp.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
当我运行这段代码时,我看到了这个异常:-
04-25 14:11:16.448: E/MediaPlayer(533): Unable to to create media player
04-25 14:11:16.458: W/System.err(533): java.io.IOException: setDataSource failed.: status=0x80000000
04-25 14:11:16.458: W/System.err(533): at android.media.MediaPlayer.setDataSource(Native Method)
04-25 14:11:16.458: W/System.err(533): at com.example.kam.MainActivity.onResume(MainActivity.java:26)
04-25 14:11:16.468: W/System.err(533): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1154)
04-25 14:11:16.468: W/System.err(533): at android.app.Activity.performResume(Activity.java:4539)
04-25 14:11:16.468: W/System.err(533): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2433)
04-25 14:11:16.468: W/System.err(533): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2471)
04-25 14:11:16.468: W/System.err(533): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1985)
04-25 14:11:16.478: W/System.err(533): at android.app.ActivityThread.access$600(ActivityThread.java:122)
04-25 14:11:16.478: W/System.err(533): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
04-25 14:11:16.478: W/System.err(533): at android.os.Handler.dispatchMessage(Handler.java:99)
04-25 14:11:16.478: W/System.err(533): at android.os.Looper.loop(Looper.java:137)
04-25 14:11:16.478: W/System.err(533): at android.app.ActivityThread.main(ActivityThread.java:4340)
04-25 14:11:16.478: W/System.err(533): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 14:11:16.489: W/System.err(533): at java.lang.reflect.Method.invoke(Method.java:511)
04-25 14:11:16.489: W/System.err(533): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-25 14:11:16.489: W/System.err(533): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-25 14:11:16.489: W/System.err(533): at dalvik.system.NativeStart.main(Native Method)
04-25 14:11:16.489: E/MediaPlayer(533): prepareAsync called in state 1
04-25 14:11:16.489: W/System.err(533): java.lang.IllegalStateException
04-25 14:11:16.499: W/System.err(533): at android.media.MediaPlayer.prepare(Native Method)
04-25 14:11:16.499: W/System.err(533): at com.example.kam.MainActivity.onResume(MainActivity.java:42)
04-25 14:11:16.499: W/System.err(533): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1154)
04-25 14:11:16.499: W/System.err(533): at android.app.Activity.performResume(Activity.java:4539)
04-25 14:11:16.499: W/System.err(533): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2433)
04-25 14:11:16.499: W/System.err(533): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2471)
04-25 14:11:16.509: W/System.err(533): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1985)
04-25 14:11:16.509: W/System.err(533): at android.app.ActivityThread.access$600(ActivityThread.java:122)
04-25 14:11:16.509: W/System.err(533): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
04-25 14:11:16.509: W/System.err(533): at android.os.Handler.dispatchMessage(Handler.java:99)
04-25 14:11:16.509: W/System.err(533): at android.os.Looper.loop(Looper.java:137)
04-25 14:11:16.509: W/System.err(533): at android.app.ActivityThread.main(ActivityThread.java:4340)
04-25 14:11:16.509: W/System.err(533): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 14:11:16.509: W/System.err(533): at java.lang.reflect.Method.invoke(Method.java:511)
04-25 14:11:16.519: W/System.err(533): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-25 14:11:16.519: W/System.err(533): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-25 14:11:16.519: W/System.err(533): at dalvik.system.NativeStart.main(Native Method)
04-25 14:11:16.519: E/MediaPlayer(533): start called in state 1
04-25 14:11:16.519: E/MediaPlayer(533): error (-38, 0)
04-25 14:11:16.669: D/gralloc_goldfish(533): Emulator without GPU emulation detected.
但是我将此代码导入另一台PC,它会毫无问题地播放。
我的错误在哪里