Reputation: 1568
I am trying to decode video samples using MediaCodec API. I am using surfaceView to show rendered samples. If i press home button, app going into pause state and surface destroyed. When i coming back to resume state, new surfaceView reference is creating, but decoder is unable to pump samples on surfaceView. so screen appearing as black. video configure: videoDecoder.configure(format, surface, null, 0); So how can i reconfigure videoDecoder in above statement. It is similar to the following problem How to keep decoding alive during screen orientation?
Upvotes: 1
Views: 4853
Reputation: 52303
The MediaCodec
API does not currently (API 19) provide a way to replace the output Surface
.
As in the other question you refer to, I think the way to deal with this will be to decode to a Surface
that isn't tied to the view hierarchy (and, hence, doesn't get torn down when the Activity
is destroyed).
If you direct the output of the MediaCodec
to a SurfaceTexture
, you can then render that texture onto the SurfaceView
. This will require a bit of GLES code. You can find the necessary pieces in the Grafika sources, but there isn't currently a full implementation of what you want (e.g. PlayMovieActivity
decodes video to a SurfaceTexture
, but that ST is part of a TextureView
, which will get torn down).
The additional rendering step will increase the GPU load, and won't work for DRM-protected video. For most devices and apps this won't matter.
See also the bigflake examples.
Update: I've added this to Grafika, with a twist. See the "Double decode" example. The output goes to a SurfaceTexture
associated with a TextureView
. If the screen is rotated (or, currently, blanked by hitting the power button), decoding continues. If you leave the activity with the "back" or "home" button, decoding stops. It works by retaining the SurfaceTexture
, attaching it to the new TextureView
.
Upvotes: 3