📜 ⬆️ ⬇️

Do not use MediaPlayer and MediaMetadataRetriever in Android

As my humble experience shows, the native MediaPlayer, MediaMetadataRetriever, as well as other classes that are based on them in one way or another (VideoView, ThumbnailUtils, for example), are extremely unreliable to use. Perhaps the problem is that they are implemented natively, and change from version to version, but the fact remains that their behavior on different devices is impossible to predict, and it does not even depend on the power of the iron.

A good example was a small project where video playback was required. The format and codec could be chosen any, I conducted tests on mp4 and avi with different codecs. On all devices that came to hand, the reproduction went smoothly and without censure. Older devices and OS versions <4.0 were not required to be supported, and I thought that there would be no problems with these formats. Then on HTC desire V it was found that several videos are not played, the built-in player in the gallery too. There was a thought that the device was rather weak, but the surprise was that almost no test videos were played on the Nexus 5. I couldn’t find any regularity - even with the same codecs, one file could be read, and the other could not. The files were not damaged, so sin remained only on the VideoView with the MediaPlayer inside.

Fortunately, there were good alternatives that work not only more reliably, but also faster:


In general, I highly recommend not using standard classes, even for small projects and “normal” common video / audio formats. Someone may disagree and say that everything works well for him. Here you can only advise on testing more files and devices ... using Genymotion, for example.

')

Source: https://habr.com/ru/post/249051/


All Articles