这是我正在开发的应用程序的示例代码。
这是我的类文件。. . .
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 更新到帧,我在搜索栏中拖动。
它在视频播放时工作正常,但在暂停时不更新。
先感谢您 。