簡體   English   中英

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

[英]How to use the VideoView .isPlaying() method?

我的目標是在播放視頻的過程中播放重復的動畫,因為我使用的是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

    }

視頻可以成功播放,但不會出現動畫,我已經確保實現了動畫,並且只需將其放在循環括號的旁邊即可正確地實現動畫,但這不是目的,因為我想在視頻時重復播放動畫玩過的!

 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,也許是因為視頻尚未開始。 此外,在您的while阻止創建新動畫的過程中,將在視頻仍在播放時創建多個動畫...

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);。

我認為您只需要刪除(AdPlayer0.isPlaying()){

添加animation.setRepeatCount(Animation.INFINITE);

繼續

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM