Saturday, 15 June 2013

android - IllegalStateException when returning to Activity containing MediaPlayer -



android - IllegalStateException when returning to Activity containing MediaPlayer -

i have activity mediaplayer , whenever launch activity (for illustration chromecast controller activity or using shareactionprovider) , homecoming activity mediaplayer, next illegalstateexception:

11-13 15:48:33.083 22342-22342/com.iosharp.android.ssplayer e/androidruntime﹕ fatal exception: main java.lang.illegalstateexception @ android.media.mediaplayer._setvideosurface(native method) @ android.media.mediaplayer.setdisplay(mediaplayer.java:733) @ com.iosharp.android.ssplayer.videoplayer.videoactivity.surfacecreated(videoactivity.java:126) @ android.view.surfaceview.updatewindow(surfaceview.java:610) @ android.view.surfaceview.onwindowvisibilitychanged(surfaceview.java:239) @ android.view.view.dispatchwindowvisibilitychanged(view.java:8170)

reading documentation says setdisplay() can called in state.

my relevant code below:

public class videoactivity extends actionbaractivity implements surfaceholder.callback, mediaplayer.onpreparedlistener, videocontrollerview.mediaplayercontrol, mediaplayer.onerrorlistener { private surfaceview msurfaceview; private mediaplayer mplayer; private videocontrollerview mcontroller; private string murl; private surfaceholder msurfaceholder; private videocastmanager mcastmanager; private mediainfo mselectedmedia; private ivideocastconsumer mvideocastconsumer; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); mcastmanager = castapplication.getcastmanager(this); setcontentview(r.layout.activity_video); msurfaceview = (surfaceview) findviewbyid(r.id.videosurface); setupactionbar(); setupcastlisteners(); bundle b = getintent().getextras(); if (b != null) { mselectedmedia = utils.tomediainfo(getintent().getbundleextra("media")); murl = mselectedmedia.getcontentid(); msurfaceholder = msurfaceview.getholder(); msurfaceholder.addcallback(this); mplayer = new mediaplayer(); mcontroller = new videocontrollerview(this, false); } } @override protected void onresume() { super.onresume(); setuplocalplayback(); if (mcastmanager != null) { mcastmanager.incrementuicounter(); } } @override public boolean ontouchevent(motionevent event) { mcontroller.show(); showactionbar(); homecoming false; } @override public void onbackpressed() { super.onbackpressed(); // hide prevent illegal state exception of getcurrentposition mcontroller.hide(); if (mplayer != null) { mplayer.reset(); } } @override protected void onpause() { super.onpause(); mcontroller.hide(); mplayer.release(); if (mcastmanager != null) { mcastmanager.decrementuicounter(); } }

well, mplayer.release(); in onpause() method, mplayer released , can't him. seek reinit or not release in onpause. seek in onstop example.

android android-mediaplayer surfaceview surfaceholder

No comments:

Post a Comment