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

发布于 2024-10-18 14:32:36 字数 363 浏览 1 评论 0原文

Android 可以播放各种视频格式,但我需要选择一种适用于所有设备的格式。

所有 Android 2.3 设备都支持完全相同的格式吗?即,如果该格式可以在模拟器中播放,是否意味着它也可以在所有硬件上播放?或者不同的设备是否支持不同的格式,具体取决于它们拥有的解码器芯片?

如果它们都相同,那么显然最好的格式是高比特率和分辨率的 H.264。如果不是,那么可以在 90% 的设备上播放的最佳编解码器/比特率/分辨率是什么? Google 是否提供某种方式来查询设备的视频功能并选择合适的格式?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一影成城 2024-10-25 14:32:36

经过在很多设备上进行测试(对于一个非常流行的应用程序的视频闪屏)。我的建议是:

video codec : H.264 
file format: .mp4
video bitrate: 256kbps
video frame/second: 24

注意:我的视频没有声音!

但即使采用此建议,某些视频仍因其分辨率而无法播放。
所以我创建了一个棘手的代码:我将所有密度的视频嵌入到我的 raw 文件夹中,向我的 VideoView 添加了一个 setOnErrorListener ,然后我每次发生错误时尝试启动较小的视频。

这是我的原始文件夹:

raw/
   splashmdpi.mp4
   splashhdpi.mp4
   splashxhdpi.mp4

这是我的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)];
    }

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)];
    }
夜空下最亮的亮点 2024-10-25 14:32:36

该模拟器对编解码器的测试很差,并且在某些方面无法正常工作。是的,设备制造商可能会在他们的 Android 版本中添加额外的编解码器。不过,您可能需要查看 Android 兼容性 并阅读有关制造商对设备上的 Android Market 的要求的更多详细信息,请参阅兼容性定义文档。不幸的是,快速浏览一下它并没有说明任何有关最低比特率的信息,因此根据您愿意支持的 Android 版本,您可能会遇到问题。

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.

绮筵 2024-10-25 14:32:36

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

相信大家可以通过MediaPlayer类来看看具体的功能。

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文