设置视频之间的时间
Set time between videos
我正在使用 phone 存储中的视图翻转器在视频视图中播放一些视频,我希望在两个视频之间有 5-10 秒的休息时间。
这是我播放多个视频的函数
FileOutputStream fos;
final String [] path;
int lengthPath;
index = 0 ;
try {
player = new VideoView(context);
path=readFileFromMemory(DashBoard.this);
if(path.length>0){
player.setVideoPath(path[index]);
}
player.setMediaController(new MediaController(this));
player.requestFocus();
player.start();
vfFlipper2.addView(player);
ViewFlipper.LayoutParams param = new ViewFlipper.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
param.gravity = Gravity.CENTER;
player.setLayoutParams(param);
player.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
index=index+1;
if(index<path.length){
player.setVideoPath(path[index]);
vfFlipper2.showNext();
player.start();
}else{
index=0;
player.setVideoPath(path[index]);
vfFlipper2.showNext();
player.start();
}
}
});
}catch(Exception e){
e.printStackTrace();
}
ReadFileMemory 函数是:
public String[] readFileFromMemory (Context activity)
{
Bitmap bitmapreturned=null;
File file;
String []fleabc = null;
int imageCount =0;
File sdCard = new File(Environment.getExternalStorageDirectory()
.getPath() + "/iDisplay/iDisplay - Videos/");
imageCount = sdCard.listFiles().length;
fleabc=new String[imageCount];
for (int count = 0; count < imageCount ; count++) {
file = new File (sdCard.listFiles()[count].getAbsolutePath());
FileInputStream streamIn=null;
fleabc[count]=file.getPath();
}
return fleabc;
}
添加一个延迟 5/7 秒的 Handler
然后在 onCompletiong
中开始新视频
这样做
@Override
public void onCompletion(MediaPlayer mp) {
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
playNextVideo();
}
}, 5000); // 5 second delay
}
private void playNextVideo()
{
index=index+1;
if(index<path.length){
player.setVideoPath(path[index]);
vfFlipper2.showNext();
player.start();
}else{
index=0;
player.setVideoPath(path[index]);
vfFlipper2.showNext();
player.start();
}
}
我正在使用 phone 存储中的视图翻转器在视频视图中播放一些视频,我希望在两个视频之间有 5-10 秒的休息时间。
这是我播放多个视频的函数
FileOutputStream fos;
final String [] path;
int lengthPath;
index = 0 ;
try {
player = new VideoView(context);
path=readFileFromMemory(DashBoard.this);
if(path.length>0){
player.setVideoPath(path[index]);
}
player.setMediaController(new MediaController(this));
player.requestFocus();
player.start();
vfFlipper2.addView(player);
ViewFlipper.LayoutParams param = new ViewFlipper.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
param.gravity = Gravity.CENTER;
player.setLayoutParams(param);
player.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
index=index+1;
if(index<path.length){
player.setVideoPath(path[index]);
vfFlipper2.showNext();
player.start();
}else{
index=0;
player.setVideoPath(path[index]);
vfFlipper2.showNext();
player.start();
}
}
});
}catch(Exception e){
e.printStackTrace();
}
ReadFileMemory 函数是:
public String[] readFileFromMemory (Context activity)
{
Bitmap bitmapreturned=null;
File file;
String []fleabc = null;
int imageCount =0;
File sdCard = new File(Environment.getExternalStorageDirectory()
.getPath() + "/iDisplay/iDisplay - Videos/");
imageCount = sdCard.listFiles().length;
fleabc=new String[imageCount];
for (int count = 0; count < imageCount ; count++) {
file = new File (sdCard.listFiles()[count].getAbsolutePath());
FileInputStream streamIn=null;
fleabc[count]=file.getPath();
}
return fleabc;
}
添加一个延迟 5/7 秒的 Handler
然后在 onCompletiong
这样做
@Override
public void onCompletion(MediaPlayer mp) {
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
playNextVideo();
}
}, 5000); // 5 second delay
}
private void playNextVideo()
{
index=index+1;
if(index<path.length){
player.setVideoPath(path[index]);
vfFlipper2.showNext();
player.start();
}else{
index=0;
player.setVideoPath(path[index]);
vfFlipper2.showNext();
player.start();
}
}