How to select which one to show in case of dual video in .mp4 file?

96 Views Asked by At

I'm using surfaceView where i'm rendering the video. I have a .mp4 file with video/hevc and video/avc. I made two threads such that they are extracted, decoded and rendered to the surface though the surfaceView. i can choose which video to show in the surface by changing this line in the thread:

 decoder.configure(format, null, null, 0);

to

 decoder.configure(format, surface, null, 0);

But how to do this dynamically on the fly with a click of a button?

1

There are 1 best solutions below

3
E.Abdel On

If you are targeting Android version since M, you can set the surface on the fly by using MediaCodec.SetOutputSurface(Surface) Note that for avoiding decoders concurrence on the same surface, a (only?) solution (bad?) is to use another hidden surface and pass it to the first decoder before setting your desirated surface to the second one