简体   繁体   English

什么视频格式将在所有Android设备上播放?

[英]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. Android可以播放各种视频格式 ,但我需要选择一种适用于所有设备的格式。

Do all Android 2.3 devices support exactly the same formats? 所有Android 2.3设备都支持完全相同的格式吗? ie 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. 如果它们完全相同,那么显然最好的格式是高比特率和分辨率的H.264。 If not, then what is the best codec/bitrate/resolution that will play on 90% of devices? 如果没有,那么90%的设备上最好的编解码器/比特率/分辨率是多少? Do Google provide some way of querying the device's video capabilities and choosing an appropriate 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. 所以我创建了一个棘手的代码:我将所有视频的所有视频嵌入到我的raw文件夹中,在我的VideoView添加了一个setOnErrorListener ,并且每次发生错误时我都尝试启动一个较小的视频。

This is my raw folder: 这是我的原始文件夹:

raw/
   splashmdpi.mp4
   splashhdpi.mp4
   splashxhdpi.mp4

and this is my java code: 这是我的java代码:

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)];
    }

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. 是的,设备制造商可能会为其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. 但是,您可能需要查看Android兼容性并阅读兼容性定义文档,了解制造商在设备上获取Android Market所需的更多详细信息。 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. 不幸的是,快速查看它并没有说明最低比特率,所以根据您愿意支持的Android版本的年龄可能存在问题。

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

I believe you can use the MediaPlayer class to see specific capabilities. 我相信您可以使用MediaPlayer类来查看特定功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 适用于所有移动设备的最佳视频格式是什么 - What is the best video format to convert to for all mobile devices Android:我应该使用什么视频格式/编码来支持大多数Android设备 - Android: What video format/encoding should I use to support most of the android devices android播放所有扩展程序的视频 - android play video of all extensions google play 上的所有设备都不支持 android 应用程序? - android app unsupported for all devices on google play? Google Play上的Android应用程序 - 与所有设备不兼容 - Android application on Google Play - incompatible with all devices Android / Google Play并非支持所有设备 - Android / Google Play Not all devices supported Android 2.1的浏览器是否支持HTML 5以及它播放的视频格式? - Does Android 2.1's Browser Support HTML 5 and What Video Format Does It Play? 在不同的浏览器中播放视频/音频文件的编码格式是什么 - what is the format to encode to play video/audio file to play in different browsers Android设备上的网络视频是在线播放还是在视频应用中播放? - Do Videos on the Web on Android Devices play inline or in an video app? 什么是所有Android Webview版本的通用视频格式(和视频/音频流编码) - What is a universal video format(and video/audio streaming codification) for all Android Webview versions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM