设置视频之间的时间

时间:2016-03-04 12:57:47

标签: android video android-videoview viewflipper

我正在使用手机存储中的视图鳍状肢在视频视图中播放一些视频,我希望在两个视频之间有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;
}

1 个答案:

答案 0 :(得分:0)

添加Handler延迟5/7秒,然后在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();
    }
}