视频无法在VideoView中恢复 [英] Video does not resume in VideoView

查看:555
本文介绍了视频无法在VideoView中恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多关于此问题的帖子.但是,在活动暂停时可以使用解决方案.我尝试了所有无效的方法.我的问题有点不同

Many posts are there for this issue.But the solutions are available for when the activity gets paused. I tried all it doesn't work. My problem is little bit different

我有一个视频视图,当用户单击该视频视图时,视频将暂停,如果他再次单击,则应恢复该视频.

I have a videoview and when the user clicks the videoview ,video will be paused and if he clicks again it should be resumed.

我在ontouchlistener中的代码段是

My code snippet in ontouchlistener is,

   videopath = getIntent().getStringExtra("path");
    imageView = ((VideoView) findViewById(R.id.imageView));
    imageView.setVideoPath(videopath);
    imageView.start();
    imageView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if(event.getAction()==MotionEvent.ACTION_UP)
                if (layout.getVisibility()==View.VISIBLE) {
                    imageView.seekTo(stopPosition);
                    imageView.resume();
                    layout.animate().translationY(-layout.getHeight()).setDuration(500);
                    layout.setVisibility(View.GONE);
                    hideSystemUI();
                } else {
                    imageView.pause();
                    stopPosition=imageView.getCurrentPosition();
                    showSystemUI();
                    layout.setVisibility(View.VISIBLE);
                    layout.animate().translationYBy(layout.getHeight());
                }
            return true;
        }
    });

我从链接中获得了此解决方案.它不起作用,仅使用resume()即可;也不起作用.

I got this solution from this link . It doesn't work and simply using resume(); is also not working.

推荐答案

之所以会发生这种情况,是因为您的设备失去了存储时间.您可以使用MediaPlayer实例,这里是如何使用

This happens because your device looses the time you've stored. You can use MediaPlayer instance, Here how you can use,

    VideoView videoView;
    MediaPlayer mp;

    videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mp) {
                    this.mp = mp;
                }
            });

    public void pause(){
        //NOT videoview.pause();
        if (mp != null){
           mp.pause();
        }
    }

    public void resume(){
        //NOT videoview.resume();
        if (mp != null){
           mp.start();
        }   
    }

//This function will be implemented under onClick method
if (!videoView.isPlaying()) {
                 resume();
                 layout.setVisibility(View.GONE);
                 hideSystemUI();//hiding navigationbar
} 
else {//initially layout visibility is GONE
                 pause();
                 stopPosition=videoView.getCurrentPosition();
                 showSystemUI();
                 layout.setVisibility(View.VISIBLE);
                 layout.animate().translationYBy(layout.getHeight());
}

这篇关于视频无法在VideoView中恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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