java 如何在Android直播中播放视频之前显示进度条?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15972050/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 21:29:47  来源:igfitidea点击:

How to show progress bar until video play in live stream Android?

javaandroidvideo-streamingandroid-videoviewlive-streaming

提问by Deepak Swami

i am working on an application where i need to play video from a remote server as live stream.

我正在开发一个应用程序,我需要将来自远程服务器的视频作为实时流播放。

which is done by me successfully. i managed every thing in my app.

这是我成功完成的。我管理我的应用程序中的每一件事。

but when video is loading i need to show a progress dialog over VideoView.

但是当视频正在加载时,我需要在 VideoView 上显示一个进度对话框。

i tried using OnPreparedListener as "how to show the progress bar before playing the video"

我尝试使用 OnPreparedListener 作为“如何在播放视频之前显示进度条

@Override
public void onPrepared(MediaPlayer mp) {
    progressbar.setVisibility(View.GONE);
    mp.start();

}

but video play after 5-7 Sec of progressbar gone. i searched a lot on Google but not found any solution for it.

但是在进度条的 5-7 秒后视频播放消失了。我在谷歌上搜索了很多,但没有找到任何解决方案。

Could anyone help me.

谁能帮助我。

Thanks in Advance.

提前致谢。

回答by Deepak Swami

have a look this one solved my problem hope help you also..

看看这个解决了我的问题希望对你也有帮助..

http://www.quicktips.in/how-to-show-progressbar-while-loading-a-video-in-android-videoview/

http://www.quicktips.in/how-to-show-progressbar-while-loading-a-video-in-android-videoview/

 progressbar.setVisibility(View.VISIBLE);

 videoView.setOnPreparedListener(new OnPreparedListener() {

            @Override
            public void onPrepared(MediaPlayer mp) {



                mp.start();

                mp.setOnVideoSizeChangedListener(new OnVideoSizeChangedListener() {

                    @Override
                    public void onVideoSizeChanged(MediaPlayer mp, int arg1, int arg2) {
                        // TODO Auto-generated method stub
                        Log.e(TAG, "Changed");
                        progressbar.setVisibility(View.GONE);
                        mp.start();
                    }
                });


            }
        });

:)

:)

回答by Munish Katoch

Unforgettably there is no OnStart Listener expose by Android. After Prepared State, the MediaPlayer goes into Started State once playback started.

令人难忘的是,Android 没有公开 OnStart 侦听器。在 Prepared State 之后,MediaPlayer 一旦开始播放就进入 Started State。

But in Prepared State only you should have sufficient buffer to play. Can you use setOnBufferingUpdateListener (MediaPlayer.OnBufferingUpdateListener listener) and print percentage of buffer. So that way you can see, if in Prepared State you have enough buffer or not.

但是只有在准备状态下,您才应该有足够的缓冲区来播放。您可以使用 setOnBufferingUpdateListener (MediaPlayer.OnBufferingUpdateListener listener) 并打印缓冲区的百分比。这样您就可以看到,如果处于准备状态,您是否有足够的缓冲区。