Android Video View does not play MP4 file on some devices

In my application, I need to play video from sdcard. Now it works great on the Galaxy S, Galaxy Tab2, but on some Chinese tabs. Like "Giada". It does not work at all.

I have 4 different activities for playing videos. The first action is a menu with a link to another activity. The problems I encountered.

  • The first video plays correctly, but the cycle is completed and the application is closed.
  • If I go to other actions to play another video, it says "Unable to play video" and is closed. For a while, he plays the same video, but does not complete and closes the application between them.

Video extension: MP4 Resolution: 1024x600 Playback from: SDCard.

Targeting Targeting Specification.

Resolution: 1024x600 Android: 4.1

Tried watching videos and SurfaceView.

Help me help, you will be sorry.

+9
android video videoview android-videoview
source share
1 answer

The answer to this question will never be the same for all devices or for all videos.

Whether a given video file will play in this player depends on three things:

  • Video container format (file type).
  • Codecs in which video (and possibly audio) streams are encoded
  • Your player supports this combination of container format and codec

Support for the codec and player / device is almost certainly the cause of the conflicting results you saw. (A codec, if you didn’t know, is essentially a repeatable mathematical formula that tells your system how to convert bits and bytes packed into a file into moving images (and vice versa, for that matter))

There is a wide variety of video codecs in video files. Support for these codecs is extremely controversial due to the history of video distribution. Many devices do not support streams encoded using certain codecs. There are many reasons for this, but the most common are the ambiguity or cost of licensing.

For example, a few years ago, almost everything was encoded in a .FLV container with the On2 VP6 / VP7 / VP8 codec. Today it causes a headache, because although On2 owned these codecs, they carefully controlled the licenses. This did not weaken until .FLV no longer began to lose its relevance, and therefore there are not so many (legitimate) software that could work with content encoded On2.

All this means that there is no silver bullet. All videos will never work on all devices, at least without the help of video players who install and use their own codecs to decode streams.

Needless to say, this does not apply to the libraries provided to you and your end users by the Android libraries installed at the factory.

So what are you doing? Well, if you do not produce a video player with your own codecs, you can most effectively solve the problem using a two-step approach:

  1. Target specific devices where you want your app to run
  2. Encode your content to use a video codec that works on all the devices you want to target. You may need to create two copies of your video if you find that there is no codec that works on all the devices that you plan to support.

Today, the broadest support is available with an MP4 container and video stream encoded using the H.264 codec (AVC). As I said, there is no silver bullet, and H.264 support is by no means universal, but this format will be played by more potential users than any other choice you can make, due to its popularity and wide support in modern desktop and mobile environments.

Some tools you may find useful:

  • MediaInfo lets you peer into MPEG-style video containers to see which codecs are in use. This will be useful in determining which devices have problems with which codecs.
  • FFmpeg is an encoding application that can convert your content to MP4 / H.264.
  • Android Supported media formats List of supported media audio / video formats.

Good luck

+16
source share

All Articles