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:
- FFmpeg library. You can compile it yourself using Android NDK. Well, but the disadvantages of this approach are obvious - you need to deal with the NDK, build it, and you can only do it under Linux. To this I did not want to waste time.
- FFmpegMediaPlayer. Actually, it is based on the first library, but you do not need to build, and an interface is already provided that is completely analogous to the native MediaPlayer. Purely for verification, I tried to use it, but for some reason the video was not drawn on the SurfaceView, while the exact same code, but with the native MediaPlayer worked without problems. Perhaps it was my cant, but I could not find a quick solution.
(UPD: As noted in the comments, this library is for audio only) - Vitamio. Also takes as a basis FFmpeg and also provides ready-made assembly. It also has its own VideoView and MediaMetadataRetriever, with an interface like the one from the Android SDK, which greatly simplifies life when creating a player. It is possible to use your FFmpeg builds, supports OS 2.1+ and almost all formats. I stopped at this library, there were no problems with it. Please note that the build does not initially have a build for x86. It is also worth expecting that your APK grows over a megabyte of ~ 8 with this library.
- There are other options, most of them use the same FFmpeg, but Vitamio completely arranged for me.
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.