【问题标题】:After pausing the video , Video is not updating in videoView while the seekbar is dragged to new position暂停视频后,将搜索栏拖到新位置时,视频不会在 videoView 中更新
【发布时间】:2012-12-03 12:32:16
【问题描述】:

这是我正在开发的应用程序的示例代码。

这是我的类文件。 . . .

public void onCreate(Bundle icicle) 
   {
     super.onCreate(icicle);
     setContentView(R.layout.main);

     sb = (SeekBar)findViewById(R.id.control_seekbar);

     mVideoView1 = (VideoView) findViewById(R.id.surface_view1);
     mVideoView1.setVideoPath("android.resource://" + getPackageName() +"/"+R.raw.play);              
     mVideoView1.pause();

     mVideoView2 = (VideoView) findViewById(R.id.surface_view2);
     mVideoView2.setVideoPath("android.resource://" + getPackageName() +"/"+R.raw.play);              
     mVideoView2.pause();

     v1 = mVideoView1.getDuration();
     v2 = mVideoView2.getDuration();

     mVideoView1.setOnPreparedListener(new OnPreparedListener() 
     {
        @Override
        public void onPrepared(MediaPlayer arg0) 
        {
            sb.setMax(mVideoView1.getDuration());
            sb.postDelayed(onEverySecond, 60);
        }
     });



     sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() 
     {  
        @Override
        public void onStopTrackingTouch(SeekBar seekBar) 
        {
            // TODO Auto-generated method stub

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) 
        {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) 
        {
            mVideoView1.seekTo(progress);
            mVideoView2.seekTo(progress);
        }
    });

   }

   private Runnable onEverySecond=new Runnable() 
   {
        @Override
        public void run() {

            if(sb != null) {
                sb.setProgress(mVideoView1.getCurrentPosition());
            }

            if(mVideoView1.isPlaying()) 
            {
                sb.postDelayed(onEverySecond, 1000);
            }

        }
    };

这是我的 xml 文件。 . . .

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent">

   <LinearLayout 
       android:id="@+id/video_ll"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:layout_above="@+id/control_btn_ll"
       android:orientation="horizontal">

        <VideoView
            android:id="@+id/surface_view1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:overScrollMode="always"/>

        <VideoView
            android:id="@+id/surface_view2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:overScrollMode="always"/>

   </LinearLayout>

   <LinearLayout 
       android:id="@+id/control_btn_ll"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_centerHorizontal="true"
       android:layout_alignParentBottom="true">

       <SeekBar
           android:id="@+id/control_seekbar"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:max="100"
           android:minHeight="1dp"
           android:minWidth="250dp" />

   </LinearLayout>

</RelativeLayout>

我有两个视频,必须同时更新,同时拖动搜索栏。 视频应该暂停,我希望 vedioView 更新到帧,我在搜索栏中拖动。

视频播放时效果很好,但暂停时不更新。

提前致谢。

【问题讨论】:

    标签: android android-videoview seekbar


    【解决方案1】:

    如果暂停,Android 视频不会在搜索后更新帧。您必须让视频播放几毫秒,然后再次暂停。这是它工作的唯一方式。

    【讨论】:

    • 我什至尝试在 100 毫秒后暂停视频。但即使我将搜索栏拖到新位置,我也只能获得我暂停的相同特定帧。
    • 尝试添加一个 OnSeekCompleteListener 并在完成搜索后让视频运行。让它播放大约 200 毫秒并暂停。
    • 但是 OnSeekCompleteListener 不能用 videoView 实现。
    • 啊,是的,对不起,我忘了提到我使用了支持此功能的 MediaPlayer。因此,我从纯 videoview 更改为 MP。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-27
    • 2012-08-04
    • 1970-01-01
    • 2021-06-28
    • 2016-09-21
    • 1970-01-01
    • 2011-06-04
    相关资源
    最近更新 更多