Android VideoView的resume和seekTo

发布于 2024-09-04 19:03:14 字数 300 浏览 13 评论 0原文

我正在我的应用程序中使用 VideoView 播放视频。单击按钮后,它会记录视频的当前位置,然后应用程序会打开浏览器并显示一些网址。按下后退按钮后,应用程序将返回视频应用程序并从中断处恢复视频。

我查看了 Android Activity 生命周期,发现一旦视频 Activity 进入前台,就会调用 onStart() 方法。因此,我在 onStart() 中创建布局并通过查找当前位置来播放视频。

我的问题是,当视频恢复时,它从一开始就缓冲,然后寻找。既然它已经第一次缓冲了,有没有办法在执行seekTo时再次消除缓冲?

谢谢 克里斯

I am playing a Video using a VideoView in my app. On the click of a button, it records the current position of the video, and the app opens up the browser with some url. On pressing the back button, the app comes back to video app and resumes the video from where it left off.

I looked at the Android Activity lifecycle and saw that onStart() method gets called once the video activity comes to the foreground. So I am creating my layout in onStart() and playing the video by seeking to the current position.

My problem is that when the video resumes, it buffers from the start and then seeks to. Since it already buffered the first time, is there a way to eliminate buffering again while doing a seekTo?

Thanks
Chris

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

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

发布评论

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

评论(2

弥繁 2024-09-11 19:03:14

我有类似的问题。我有一个 OnPreparedListener 在开始之前执行seekTo。除了视频开头出现音频故障外,seekTo 可以正常工作,就好像视频开始播放然后进行搜索一样。我不知道我的代码是否有助于解决所描述的缓冲问题,但它可能有助于阐明它。

  mVideoView.setVisibility(View.VISIBLE);
  //get current window information, and set format, set it up differently, if you need some special effects
  getWindow().setFormat(PixelFormat.TRANSLUCENT);
  //mVideoView.setVideoURI(Uri.parse(path));
  mVideoView.setVideoPath(path);
  //get focus, before playing the video.
  mVideoView.requestFocus();
  mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
           public void onPrepared(MediaPlayer mp) {                         
           mVideoView.seekTo(mImageSeek);
           mVideoView.start();
        }
     });

I am having a similar problem. I have an OnPreparedListener that does the seekTo prior to the start. The seekTo works except that there is an audio glitch that is coming from the very beginning of the video, as if it is starting to play and then seeking. I don't know if my code would help the buffering problem described but it may help illuminate it.

  mVideoView.setVisibility(View.VISIBLE);
  //get current window information, and set format, set it up differently, if you need some special effects
  getWindow().setFormat(PixelFormat.TRANSLUCENT);
  //mVideoView.setVideoURI(Uri.parse(path));
  mVideoView.setVideoPath(path);
  //get focus, before playing the video.
  mVideoView.requestFocus();
  mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
           public void onPrepared(MediaPlayer mp) {                         
           mVideoView.seekTo(mImageSeek);
           mVideoView.start();
        }
     });
赏烟花じ飞满天 2024-09-11 19:03:14

代码

videoview = (VideoView) findViewById(R.id.videoview_play);
videoview.setVideoPath(dir + videoName);
//get focus, before playing the video.
videoview.setMediaController(new MediaController(this));
videoview.requestFocus();
videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                                       public void onPrepared(MediaPlayer mp){                         
                                         videoview.seekTo(5000);
                                         videoview.start();
                                       }
                                });

定义您的资源视频视图,然后使用您必须添加的 .setMediaController(new MediaController(this));
希望

videoview.requestFocus();

在使用PrepareListener之前

它能帮助你

Define your Resource videoview then use this code

videoview = (VideoView) findViewById(R.id.videoview_play);
videoview.setVideoPath(dir + videoName);
//get focus, before playing the video.
videoview.setMediaController(new MediaController(this));
videoview.requestFocus();
videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                                       public void onPrepared(MediaPlayer mp){                         
                                         videoview.seekTo(5000);
                                         videoview.start();
                                       }
                                });

you have to add .setMediaController(new MediaController(this));
and

videoview.requestFocus();

before using the PrepareListener

hope it will help you

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