【问题标题】:Android video starts playing one minute after buffering in doneAndroid 视频在缓冲完成后一分钟开始播放
【发布时间】:2013-01-02 17:37:29
【问题描述】:

我使用 vitamio 库来播放 rtsp。 虽然我的代码中有videoView.start();,但视频在缓冲完成后一分钟开始播放!

但如果我在缓冲完成后改变方向,视频会立即开始播放! 我有以下代码,并且我知道更改方向会调用此方法:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    if (videoView != null)
        videoView.setVideoLayout(VideoView.VIDEO_LAYOUT_SCALE, 0);
    super.onConfigurationChanged(newConfig);
}

但我不知道究竟是什么让视频开始播放,除了改变方向之外,我无法强制它开始播放(缓冲完成后立即)。请帮忙...

【问题讨论】:

    标签: android video-streaming android-videoview


    【解决方案1】:

    我遇到过当 VideoView 的维度为 0 时,视频无法播放。 确保您设置了初始尺寸。

    此外,我会尝试从头开始设置布局: videoView.setVideoLayout(VideoView.VIDEO_LAYOUT_SCALE, 0);

    我会在收到 oncVideoSizeChanged 回调后设置尺寸,例如,

    public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
    
                FrameLayout.LayoutParams vLayout = (FrameLayout.LayoutParams) mSurfaceView.getLayoutParams();
                vLayout.width = getWindowManager().getDefaultDisplay().getWidth();
                vLayout.height = getWindowManager().getDefaultDisplay().getHeight();
    
                float aspectRatio = (float) width / height;
                float screenRatio = (float) vLayout.width / vLayout.height;
                float topMargin = 0, leftMargin = 0;
    
                if (screenRatio < aspectRatio)
                    topMargin = (float) vLayout.height
                            - ((float) vLayout.width / aspectRatio);
                else if (screenRatio > aspectRatio)
                    leftMargin = (float) vLayout.width - (vLayout.height * aspectRatio);
    
                vLayout.setMargins((int) leftMargin, (int) topMargin, 0, 0);
                mSurfaceView.setLayoutParams(vLayout);
            }
    

    【讨论】:

    • 请告诉我如何设置初始尺寸。应该在 XML 或 Java 文件中完成吗?此外,从一开始就设置布局并没有帮助。
    • 通常,一旦我们收到 onVideoSizeChanged 回调,我会设置尺寸。我已经更新了答案,假设 videoview 位于 FrameLayout
    • 感谢您的代码,但它并没有解决问题。我调试了我的代码,发现视频实际上开始播放,但在 Looper.Class 中再次停止以进行缓冲,并且通过减小缓冲区大小,它可以比以前更快地启动。 @florianpilz
    • 你是如何减小缓冲区大小的?
    • 嗨@NimaK,确切的缓冲区大小应该是多少,我正在使用 vitamio 和 rmtp 流...
    猜你喜欢
    • 2016-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-06
    相关资源
    最近更新 更多