android - Service is not starting -
i have written service streaming url. there twitter button open link browser. when clicked button start service in button event, not starting. service's codes here;
public class mymediaplayerservice extends service implements onbufferingupdatelistener, oncompletionlistener, onpreparedlistener, onvideosizechangedlistener, surfaceholder.callback { private string path = "http://someurl.m3u8"; private mediaplayer mmediaplayer; private static final string media = "media";; private boolean misvideosizeknown = false; private boolean misvideoreadytobeplayed = false; private int mvideowidth; private int mvideoheight; @override public ibinder onbind(intent intent) { return null; } @override public void oncreate() { super.oncreate(); mmediaplayer = new mediaplayer(this); } public void onbufferingupdate(mediaplayer arg0, int percent) { } public void oncompletion(mediaplayer arg0) { } public void onvideosizechanged(mediaplayer mp, int width, int height) { if (width == 0 || height == 0) { return; } misvideosizeknown = true; mvideowidth = width; mvideoheight = height; if (misvideoreadytobeplayed && misvideosizeknown) { startvideoplayback(); } } public void onprepared(mediaplayer mediaplayer) { misvideoreadytobeplayed = true; if (misvideoreadytobeplayed && misvideosizeknown) { startvideoplayback(); } } public void surfacechanged(surfaceholder surfaceholder, int i, int j, int k) { } public void surfacedestroyed(surfaceholder surfaceholder) { } public void surfacecreated(surfaceholder holder) { } public void onpause() { releasemediaplayer(); docleanup(); } public void ondestroy() { super.ondestroy(); releasemediaplayer(); docleanup(); } private void releasemediaplayer() { if (mmediaplayer != null) { mmediaplayer.release(); mmediaplayer = null; } } private void docleanup() { mvideowidth = 0; mvideoheight = 0; misvideoreadytobeplayed = false; misvideosizeknown = false; } private void startvideoplayback() { mmediaplayer.start(); } @override public int onstartcommand(intent intent, int flags, int startid) { docleanup(); try { mmediaplayer.setdatasource(path); mmediaplayer.prepare(); mmediaplayer.setonbufferingupdatelistener(this); mmediaplayer.setoncompletionlistener(this); mmediaplayer.setonpreparedlistener(this); mmediaplayer.setonvideosizechangedlistener(this); mmediaplayer.getmetadata(); mmediaplayer.start(); } catch (exception e) { e.printstacktrace(); } return start_not_sticky; } }
also have started service in button event this;
public void onclick(view v) { intent browserintent = new intent(intent.action_view, uri.parse("https://twitter.com/standart_fm")); intent svc = new intent(mainactivity.this, mymediaplayerservice.class); //startservice(new intent(mainactivity.this, myservice.class)); startservice(svc); startactivity(browserintent); }
the log cat is;
07-31 14:44:15.392: d/vitamio[player](562): thread audio_output end 07-31 14:44:15.419: d/vitamio[player](562): thread audio_decode end 07-31 14:44:15.440: i/vitamio[player](562): close stream audio end 07-31 14:44:15.440: i/vitamio[player](562): close avformat begin 07-31 14:44:15.450: i/vitamio[player](562): close avformat end 07-31 14:44:15.450: i/vitamio[player](562): free videopic begin 07-31 14:44:15.450: i/vitamio[player](562): free videopic 2 end 07-31 14:44:15.450: i/vitamio[player](562): free subpic begin 07-31 14:44:15.450: i/vitamio[player](562): free subpic 1 end 07-31 14:44:15.450: i/vitamio[player](562): free audioframe begin 07-31 14:44:15.450: i/vitamio[player](562): free audioframe 8 end 07-31 14:44:15.450: i/vitamio[player](562): delete global ref begin 07-31 14:44:15.450: i/vitamio[player](562): delete global ref end 07-31 14:44:15.450: i/vitamio[player](562): file close end 07-31 14:44:15.450: d/vitamio[player](562): thread notify end 07-31 14:44:15.460: i/vitamio[player](562): vplayer release end
so. how can run stream service when twitter activity has started?
Comments
Post a Comment