如何发挥利用videoview通过搜索栏或进度条控制的视频? [英] How to play a video using videoview controlled by a seekBar or Progress bar?
问题描述
寻找了几个小时后,我问这个,任何相关答案欢迎。
After searching for many hours , i am asking this, any related answers are welcomed . .
我有我的R.raw文件夹中的视频和我玩这两个videoview同时持续时间相同的,这里是我的code,
I'm having a video in my R.raw folder and i am playing it in two videoview of same duration simultaneously , here is my code ,
sb = (SeekBar)findViewById(R.id.control_seekbar);
mVideoView1 = (VideoView) findViewById(R.id.surface_view1);
mVideoView1.setVideoPath("android.resource://" + getPackageName() +"/"+R.raw.play1);
mVideoView1.start();
mVideoView2 = (VideoView) findViewById(R.id.surface_view2);
mVideoView2.setVideoPath("android.resource://" + getPackageName() +"/"+R.raw.play2);
mVideoView2.start();
v1 = mVideoView1.getDuration();
v2 = mVideoView2.getDuration();
mVideoView1.setOnPreparedListener(new OnPreparedListener()
{
@Override
public void onPrepared(MediaPlayer arg0)
{
sb.setMax(mVideoView1.getDuration()+3);
sb.postDelayed(onEverySecond, 60);
}
});
sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
@Override
public void onStopTrackingTouch(SeekBar seekBar)
{
mVideoView1.seekTo(sb.getProgress());
mVideoView2.seekTo(sb.getProgress());
}
@Override
public void onStartTrackingTouch(SeekBar seekBar)
{
mVideoView1.seekTo(sb.getProgress());
mVideoView2.seekTo(sb.getProgress());
}
@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);
if(mVideoView1.getDuration() <= sb.getProgress())
{
mVideoView1.seekTo(0);
mVideoView2.seekTo(0);
}
}
}
};
和我可以拖动搜索栏到新的位置,它是由新位置正常播放。
and i could drag the seekbar to the new position and it is playing from the new position correctly .
但我不想开始播放视频。它应该是暂停(),并为我拖累了搜索栏,在videoview应该更新到相应的位置。
But i dont want to play the video initially . It should be in pause() and as i drag the seekbar, the videoview should update to the respective position .
当我改变mVideoView.start()暂停(),我只能看到黑屏,并在videoview搜索栏位置变化没有更新。
When i change the mVideoView.start() to pause() , i could see only a blank black screen and no update for the seekbar position change in the videoview .
在什么样的方式我可以实现它。
in what way i could achieve it .
推荐答案
您必须把媒体控制器在videoview。
You have to put a media controller in your videoview.
MediaController mediaController = new MediaController(context);
myVideoView.setMediaController(mediaController).
现在当你在你的视频点击播放,暂停按钮将显示。
Now when you click on your video the play, pause buttons will show.
这篇关于如何发挥利用videoview通过搜索栏或进度条控制的视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!