如何使用VideoView .isPlaying()方法?

时间:2016-06-06 15:29:37

标签: java android

我的目标是在播放视频的过程中播放重复动画,因为我正在使用VideoView我认为我也可以利用.isPlaying方法解决实现此然而while循环根本不执行

    Floater0 = (ImageView) findViewById(R.id.Floater0);
    AdPlayer0 = (VideoView) findViewById(R.id.AdPlayer);

    ConvertedSource = Uri.parse("android.resource://"+ getPackageName()+ "/" + R.raw.kitkat);
    AdPlayer0.setVideoURI(ConvertedSource);
    AdPlayer0.start();

    while (AdPlayer0.isPlaying()){
        TranslateAnimation animation = new TranslateAnimation(answer,  answer, 0,  height * -1); // xfrom , xto, y from,y to
        animation.setDuration(5000);  // animation duration influences the speed of full execution
        Floater0.setVisibility(View.VISIBLE); //show it
        Floater0.startAnimation(animation);  // start animation

    }

视频播放成功但动画没有出现,我已经确保动画已经实现并且只需将其放在循环的大括号旁边就可以了,但是这不是我想重复播放动画的目的视频播放时!

3 个答案:

答案 0 :(得分:1)

 AdPlayer0.start();

 while (AdPlayer0.isPlaying()){
        TranslateAnimation animation = new TranslateAnimation(answer,  answer, 0,  height * -1); // xfrom , xto, y from,y to
        animation.setDuration(5000);  // animation duration influences the speed of full execution
        Floater0.setVisibility(View.VISIBLE); //show it
        Floater0.startAnimation(animation);  // start animation

    }

也许视频没有时间加载,启动后你直接调用while,但isPlaying应该返回false,因为视频还没有启动。此外,在您创建新动画时,您将在视频播放时创建多个动画......

答案 1 :(得分:1)

TranslateAnimation animation = new TranslateAnimation(answer,  answer, 0,  height * -1); // xfrom , xto, y from,y to
animation.setDuration(5000);
Floater0.setVisibility(View.VISIBLE); //show it
Floater0.startAnimation(animation);
animation.setAnimationListener(new Animation.AnimationListener() {

@Override
public void onAnimationStart(Animation animation) {
}

@Override
public void onAnimationRepeat(Animation animation) {
}

@Override
public void onAnimationEnd(Animation animation) {
    if (AdPlayer0.isPlaying()) {
        Floater0.startAnimation(animation);
    }
}

对于您的视频观看,请使用setOnCompletionListener查找视频完成播放。在此侦听器内停止动画并隐藏Floater0.setVisibility(View.GONE);

答案 2 :(得分:1)

我认为你只需要删除while(AdPlayer0.isPlaying()){

添加animation.setRepeatCount(Animation.INFINITE);

    animation.setAnimationListener(new AnimationListener() {
    @Override
    public void onAnimationEnd(Animation arg0) {
        Floater0.stopAnimation(animation);
}