Reputation: 17
i have this code for play radio stream on internet, this code like :-
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;
}
}
when i run this code i see this exception :-
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.
but i import this code to another PC, it will play without any problem.
where my error founded
Upvotes: 1
Views: 220
Reputation: 5578
My guess would be that you're never calling release()
on your MediaPlayer
. A simple way (at least if I'm reading the logcat
correctly) to solve your problem would be to place a reset()
call before your instantiation. Like this:
mp.reset();
mp.setDataSource("http://radio.arabhosters.com:8015/");
One thing though: you should read the whole MediaPlayer state diagram to really understand what you should be doing.
Upvotes: 1