我的Android MediaPlayer同步问题 [英] My Android MediaPlayer synchronization problems

查看:204
本文介绍了我的Android MediaPlayer同步问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Android媒体播放器,可以在一个屏幕上同时播放多个视频.因此,基本上,一个媒体播放器屏幕分为4个部分,其中4个mediaPlayer实例粘合在一起,并且每个部分都播放给定的视频.

I have a simple Android media player that can play multiple videos simultaneously on a single screen. So basically a single media player screen is divided into 4 parts, with 4 mediaPlayer instance glued together, and each part plays a given video.

当我的视频文件本地存储在设备上时,它几乎可以正常工作.存在同步问题,但次要问题.但是,当我输入HTTP流的URL时,会出现严重的同步问题.问题是什么?通常,如何解决同步问题?

It works almost OK when my video files are stored locally on the device. There are synchronization problems, but minor. But when I input a URL for HTTP streaming, there is significant synchronization problems. What is the problem? Generally, how can I remove the synchronization problems?

我唯一能做的就是首先实例化媒体播放器并prepare(),然后一个接一个地调用start(),这样至少开始时间彼此接近.不过效果不大.

The only thing I could do was first instantiate the mediaplayers and prepare() them, then call start() one after the other so at least the start times be close to eachother. It doesn't have much effect though.

这里有一个返回每个mediaplayer实例的方法:

Here I have a method that return each of the mediaplayer instances:

MediaPlayer mediaPreparation(String filename, boolean setMute) {
    String url = "myURL"; // your URL here
    // create mediaplayer instance
    MediaPlayer mediaPlayer = new MediaPlayer();
    if (setMute) {
        mediaPlayer.setVolume(0, 0);
    }
    try {

        mediaPlayer.setDataSource(url);
        mediaPlayer.prepare();

    } catch (IOException e) {
    }

    mediaPlayer.setLooping(true);
    // mediaPlayer.start();
    return mediaPlayer;
}

然后我一一开始:

mp[0].start();
mp[1].start();
mp[2].start();
mp[3].start();

推荐答案

我不确定是否有任何Android媒体播放器提供此功能.

I'm not sure if any Android media player offers this functionality.

我怀疑还可能存在设备依赖性,因为硬件中不同的设备可能具有不同的功能来解码和播放多个视频,并且如果您的某些视频必须使用SW解码等,则速度会慢得多.

I suspect there may be device dependencies also, as different devices may have different capabilities in the HW to decode and play multiple videos, and if some of your videos have to use SW decoding etc they will be much slower.

它可能无法满足您的需求,但是在终端设备上提供像这样的视频网格的一种常见方法是在服务器端将视频合并在一起,然后将其作为单个视频流传递到设备.

It may not meet your needs, but a common way to provide a grid of videos like this on an end device is to merge the videos together on the server side and deliver it to the device as a single video stream.

更新

要注意的另一件事是,如果使用MediaCodec并利用HW编解码器-如果视频具有不同的视频配置文件,这也可能导致不同的解码延迟.

One other thing to be aware of if using MediaCodec and leveraging the HW codecs - if the videos have different video profiles this can cause different decoding latency also.

这与视频的编码方式有关-简单来说,如果特定帧引用了来自其后的帧中的信息(一种常见的压缩方法),则解码器需要缓冲该帧直到其被引用为止.构图也.对于使用基准配置文件的更简单的压缩方法,无需使用此技术,因此不必进行缓冲,因此可能具有较低的延迟.对于不同的硬件供应商来说,这似乎也有所不同-请参阅Intel的本说明,尤其是末尾的低延迟"部分:

This is to do with how the videos are encoded - in simple terms if a particular frame refers to information from a frame that comes after it (a common compression approach) then the decoder needs to buffer the frame until it has the refereed to frame also. Simpler compression approaches, for using Baseline profile, do not use this technique so don't have to buffer and hence may have lower latency. This appears to be different for different HW vendors also - see this note from Intel, in particular the low latency section at the end:

我怀疑针对此特定方面的最佳方法是针对最低的公共控制者-仅使用基线"配置文件,否则尝试将所有视频的显示延迟比您可以从任何单个视频获得的最大延迟更长的时间.

I suspect the best approach to this particular aspect is to aim for the lowest common dominator - either only use Baseline profile or else try to delay all video display by some factor longer than the maximum latency you can expect from any individual video.

这篇关于我的Android MediaPlayer同步问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆