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 the format will play in the emulator, does that mean it will also play on all hardware? Or do different devices support different formats depending on what decoder chips they have?
If they are all the same then obviously the best format is H.264 at a high bitrate and resolution. If not, then what is the best codec/bitrate/resolution that will play on 90% of devices? Do Google provide some way of querying the device's video capabilities and choosing an appropriate format?
MPEG-2 TS media files only.
AVI (Audio Video Interleave) works with nearly every web browser on Windows, Mac and Linux machines. Developed by Microsoft, AVI offers the highest quality but also large file sizes. It is supported by YouTube and works well for TV viewing.
Video - We recommend using MP4 video (or M4V) for compatibility with both iOS and Android.
The AVI format is not supported on android devices. Most of the android users are looking for the easy way to play the AVI files on their android tablets and smartphones. In Android Mobile device you can't play the AVI file without converting them into the supported format.
After testing on a lot of devices(for the video splashscreen of a very popular app). My recommendations are:
video codec : H.264 file format: .mp4 video bitrate: 256kbps video 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:
int densityoffset = 0; VideoView video = new VideoView(this); video.setOnPreparedListener(new OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { video.start(); } } video.setOnErrorListener(new OnErrorListener() { @Override public boolean onError(MediaPlayer mp, int what, int extra) { densityoffset++; String suff = getDensitySuffix(getContext(), densityoffset); video.setVideoPath("android.resource://com.example.packagename/raw/splash"+suff); if(offset>5) return false; else return true; } }); String suff = 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){ int dens = 2; int d = getContext().getResources().getDisplayMetrics().densityDpi if(d==DisplayMetrics.DENSITY_LOW) dens = 0; else if(d==DisplayMetrics.DENSITY_MEDIUM) dens = 1; else if(d==DisplayMetrics.DENSITY_HIGH)) dens = 2; else if(d==DisplayMetrics.DENSITY_XHIGH)) dens = 3; return suffix[Math.max(0, dens-offset)]; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With