Error on stream media on android -
i have code play radio stream on internet, code :-
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 menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } }
when run code see exception :-
04-25 14:11:16.448: e/mediaplayer(533): unable 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): @ android.media.mediaplayer.setdatasource(native method) 04-25 14:11:16.458: w/system.err(533): @ com.example.kam.mainactivity.onresume(mainactivity.java:26) 04-25 14:11:16.468: w/system.err(533): @ android.app.instrumentation.callactivityonresume(instrumentation.java:1154) 04-25 14:11:16.468: w/system.err(533): @ android.app.activity.performresume(activity.java:4539) 04-25 14:11:16.468: w/system.err(533): @ android.app.activitythread.performresumeactivity(activitythread.java:2433) 04-25 14:11:16.468: w/system.err(533): @ android.app.activitythread.handleresumeactivity(activitythread.java:2471) 04-25 14:11:16.468: w/system.err(533): @ android.app.activitythread.handlelaunchactivity(activitythread.java:1985) 04-25 14:11:16.478: w/system.err(533): @ android.app.activitythread.access$600(activitythread.java:122) 04-25 14:11:16.478: w/system.err(533): @ android.app.activitythread$h.handlemessage(activitythread.java:1146) 04-25 14:11:16.478: w/system.err(533): @ android.os.handler.dispatchmessage(handler.java:99) 04-25 14:11:16.478: w/system.err(533): @ android.os.looper.loop(looper.java:137) 04-25 14:11:16.478: w/system.err(533): @ android.app.activitythread.main(activitythread.java:4340) 04-25 14:11:16.478: w/system.err(533): @ java.lang.reflect.method.invokenative(native method) 04-25 14:11:16.489: w/system.err(533): @ java.lang.reflect.method.invoke(method.java:511) 04-25 14:11:16.489: w/system.err(533): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:784) 04-25 14:11:16.489: w/system.err(533): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:551) 04-25 14:11:16.489: w/system.err(533): @ 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): @ android.media.mediaplayer.prepare(native method) 04-25 14:11:16.499: w/system.err(533): @ com.example.kam.mainactivity.onresume(mainactivity.java:42) 04-25 14:11:16.499: w/system.err(533): @ android.app.instrumentation.callactivityonresume(instrumentation.java:1154) 04-25 14:11:16.499: w/system.err(533): @ android.app.activity.performresume(activity.java:4539) 04-25 14:11:16.499: w/system.err(533): @ android.app.activitythread.performresumeactivity(activitythread.java:2433) 04-25 14:11:16.499: w/system.err(533): @ android.app.activitythread.handleresumeactivity(activitythread.java:2471) 04-25 14:11:16.509: w/system.err(533): @ android.app.activitythread.handlelaunchactivity(activitythread.java:1985) 04-25 14:11:16.509: w/system.err(533): @ android.app.activitythread.access$600(activitythread.java:122) 04-25 14:11:16.509: w/system.err(533): @ android.app.activitythread$h.handlemessage(activitythread.java:1146) 04-25 14:11:16.509: w/system.err(533): @ android.os.handler.dispatchmessage(handler.java:99) 04-25 14:11:16.509: w/system.err(533): @ android.os.looper.loop(looper.java:137) 04-25 14:11:16.509: w/system.err(533): @ android.app.activitythread.main(activitythread.java:4340) 04-25 14:11:16.509: w/system.err(533): @ java.lang.reflect.method.invokenative(native method) 04-25 14:11:16.509: w/system.err(533): @ java.lang.reflect.method.invoke(method.java:511) 04-25 14:11:16.519: w/system.err(533): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:784) 04-25 14:11:16.519: w/system.err(533): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:551) 04-25 14:11:16.519: w/system.err(533): @ 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 import code pc, play without problem.
where error founded
my guess you're never calling release()
on mediaplayer
. simple way (at least if i'm reading logcat
correctly) solve problem place reset()
call before instantiation. this:
mp.reset(); mp.setdatasource("http://radio.arabhosters.com:8015/");
one thing though: should read whole mediaplayer state diagram understand should doing.