4

我正在开发一个聊天,我们有高质量的表情符号,扩展名为 mp4(文件大小约为 300kb)。GIF 格式由于质量差且颜色有限 (256) 而未被使用。
我需要将 ListView 中的文件显示为循环视频。现在我正在尝试使用 TextureView 和 MediaCodec 类来做到这一点。来源可以在https://github.com/google/grafika找到。
问题是,当您尝试同时播放 4 个以上的视频时,会 在 android.media.MediaCodec.dequeueOutputBuffer 发生错误 IllegalStateException。我认为这是因为内存消耗大,在我的设备(HTC ONE M7)上播放四个视频时,处理器负载超过 60%!
我怎么解决这个问题?也许我需要使用第三方编解码器?
或者使用视频显示笑脸的想法很糟糕,我需要放弃它并使用 GIF 之类的东西?

4

1 回答 1

1

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.

于 2014-11-21T16:50:14.057 回答