Skip to content Skip to sidebar Skip to footer

What Video Format Will Play On All Android Devices?

Android can play a variety of video formats, but I need to choose one format that will work on all devices. Do all Android 2.3 devices support exactly the same formats? i.e. if th

Solution 1:

After testing on a lot of devices(for the video splashscreen of a very popular app). My recommendations are:

video codec :H.264file format:.mp4video bitrate:256kbpsvideo frame/second:24

Note:My video has no sound!!

But even with this recommendation, some videos will not work because of its resolution. So i create a tricky code: I embed all my videos for all the density in my raw folder, added an setOnErrorListener to my VideoView and i try to launch a smaller video each time an error occured.

This is my raw folder:

raw/
   splashmdpi.mp4
   splashhdpi.mp4
   splashxhdpi.mp4

and this is my java code:

intdensityoffset=0;
VideoViewvideo=newVideoView(this);

video.setOnPreparedListener(newOnPreparedListener() {
             @OverridepublicvoidonPrepared(MediaPlayer mp) {
                    video.start();
                    }
 }

video.setOnErrorListener(newOnErrorListener() {
            @OverridepublicbooleanonError(MediaPlayer mp, int what, int extra) {
                densityoffset++;
                Stringsuff= getDensitySuffix(getContext(), densityoffset);
                video.setVideoPath("android.resource://com.example.packagename/raw/splash"+suff);
                if(offset>5)
                    returnfalse;
                elsereturntrue;
                }
            });

Stringsuff= getDensitySuffix(this,offset);
video.setVideoPath("android.resource://com.example.packagename/raw/splash"+suff);

private String suffix[]={"ldpi","mdpi","hdpi","xhdpi"};

/**
*Return the suffix concerning your device less offset value
**/private String getDensitySuffix(Context ctx, int offset){
        intdens=2;
        intd= getContext().getResources().getDisplayMetrics().densityDpi
        if(d==DisplayMetrics.DENSITY_LOW)
            dens = 0;
        elseif(d==DisplayMetrics.DENSITY_MEDIUM)
                dens = 1;
            elseif(d==DisplayMetrics.DENSITY_HIGH))
                    dens = 2;
                elseif(d==DisplayMetrics.DENSITY_XHIGH))
                        dens = 3;   
        return suffix[Math.max(0, dens-offset)];
    }

Solution 2:

The emulator is a poor test of codecs and isn't functional in a few areas. And yes device manufacturers may add additional codecs to their build of Android. However you may want to check out the Android Compatibility and read the Compatibility Definition Document for more details as to what is required by the manufacturer get Android Market on the device. Unfortunately a quick look through it doesn't state anything about minimum bitrate so depending on how old a version of Android you are willing to support you may have issues there.

Solution 3:

http://developer.android.com/guide/appendix/media-formats.html

I believe you can use the MediaPlayer class to see specific capabilities.

Post a Comment for "What Video Format Will Play On All Android Devices?"