I am developing a chat and we have high quality emoticons with extension mp4 (file size of about 300kb). GIF format is not used because of the poor quality and limited colors (256).
I need to display the files in the ListView as cyclic video.
Now I'm trying to do this using TextureView and MediaCodec classes.
Sources can be found at https://github.com/google/grafika.
The problem is that when you try to play more than 4 video simultaneously, an error occurs
IllegalStateException at android.media.MediaCodec.dequeueOutputBuffer.
I think this happens because of the large memory consumption,
on my device (HTC ONE M7) while playing four videos, the processor is loaded more than 60% !
How can I solve this problem? Maybe I need to use third party codecs?
Or the idea of using video to display smileys is bad and I need to give it up and use something like GIF ?

- 1,530
- 17
- 41
-
You can't start a thread within a thread on android. You have to create a separate thread task for it and let android's worker threads handle them, who then in turn feed back information to your UI thread. Asynctask is good for loading small videos, but for long term applications you're going to need a Service. – G_V Nov 21 '14 at 08:23
-
Well, there are only 4 kworkers to my knowledge and I guess they're maxed out with 4 videos. – G_V Nov 21 '14 at 09:10
-
All videos are already playing in different threads. – Dmitriy Puchkov Nov 21 '14 at 09:10
-
It depends on the quality of the video, can simultaneously play 8 videos with bad quality... – Dmitriy Puchkov Nov 21 '14 at 09:13
-
I belive this is the platform limitation, you can't create much decoder's instances If you need more you have to choose another way – Marlon Nov 21 '14 at 14:46
1 Answers
There is a limit on the number of simultaneous decoders, if for no other reason than at some point you'll exceed the maximum bandwidth of the hardware. On some devices I've seen it switch to software decoding after two hardware decoders are configured. AFAIK there's no enforced behavior here.
One possible solution to your problem is to have a single multiplexed video, where you have all of your emoticons in a single .mp4 file. Play that into a SurfaceTexture, which is then used as a "sprite sheet". This approach requires that all animations have roughly the same number of frames, so you may have to adjust some or just pad out the sequence.
Update: according to this link, the 'M' release is scheduled to add MediaCodecInfo.CodecCapabilities.getMaxSupportedInstances()
, which provides "a hint for the max number of the supported concurrent codec instances." Doesn't really help with your issue, but at least it'd give you a number. Hopefully the API will take the video resolution(s) into account.

- 51,356
- 5
- 116
- 166
-
Thank you, I'm still convinced the bosses that it is better to use GIF. – Dmitriy Puchkov Nov 24 '14 at 07:03