I'm trying to show a video stream that starts in one activity of my application and follows the user to other activities in the application without having to re-prepare it. A bit of a pause on activity change is OK, but it shouldn't restart. Everything's working fine in one activity, but when switching activities the MediaPlayer
doesn't seem to want to connect to the new SurfaceHolder
. The audio works beautifully though, with barely a hitch.
I've been trying to do this via a subclass of SurfaceView
initialized with the application context. (Re-siting application-context views across activities seems to work fine when I instead use simple views such as Button
, so I think that's not the problem.) In the constructor I create the MediaPlayer object, set the listeners and datasource (an MP4 stream via HTTP--and yeah, I verified that I can play it with a normal usage of MediaPlayer), and call prepareAsync
. In my SurfaceHolder.Callback
's surfaceCreated
method I call setDisplay
and (if the player has finished preparing) start
. In the surfaceDestroyed
method I call pause
. And in the prepare callback if the surface has already been created I call start.
I'm at a loss of what to do at this point. Any ideas?
MediaPlayer
use that can continue playing video through an orientation change, that would probably include what I need to make this work. Unfortunately I haven't been able to find any such online. – Matt Tsōnto Jul 21 '11 at 00:34