Question

import android.annotation.TargetApi;
import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.VideoView;


public class FullscreenActivity extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_fullscreen);



        VideoView vv1 = (VideoView) findViewById(R.id.fullscreen_content);      
            vv1.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.intro_video_part1);
            vv1.start();


        vv1.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mp) {
                VideoView vv2 = (VideoView) findViewById(R.id.fullscreen_content);      
                vv2.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.intro_video_part2);
                vv2.start();
            }

        });

        vv2.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mp) {
                VideoView vv3 = (VideoView) findViewById(R.id.fullscreen_content);      
                vv3.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.intro_video_part3);
                vv3.start();
            }
        });


        vv3.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mp) {
                VideoView vv4 = (VideoView) findViewById(R.id.fullscreen_content);      
                vv4.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.intro_video_part4);
                vv4.start();
            }

        });


        vv4.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mp) {
                VideoView vv42 = (VideoView) findViewById(R.id.fullscreen_content);      
                vv42.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.intro_video_part4_2);
                vv42.start();
            }
        });


        vv42.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mp) {
                VideoView vv5 = (VideoView) findViewById(R.id.fullscreen_content);      
                vv5.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.intro_video_part5);
                vv5.start();
            }
        });


    }

}

hey everyone

so this is the code i am having at the moment. Basically what I want is to display 6 videos in a row, one after another. So I got up to this but now he tells me that vv2 (and every after) CAN NOT BE RESOLVED.

I am Javascript beginner so I have no idea what that means, only I think he doesn't have that variable set cause its defined in onCompletion function.

So how can I get vv2 out of the onCompletion?

Or is there any other possible way? Maybe some loop with $i++?

Was it helpful?

Solution

vv2 and the others cannot be resolved because you declared them locally inside the onCompletion methods. So yes, you should use a counter or something and then play the videos that way.

public class FullscreenActivity extends Activity {

    private int[] data = new int[]{R.raw.intro_video_part1, R.raw.intro_video_part2,
     R.raw.intro_video_part3, R.raw.intro_video_part4, R.raw.intro_video_part5, R.raw.intro_video_part6};

    int counter = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_fullscreen);

    VideoView vv1 = (VideoView) findViewById(R.id.fullscreen_content);      
                vv1.setVideoPath("android.resource://" + getPackageName() + "/" + data[counter]);
                vv1.start();

            vv1.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                public void onCompletion(MediaPlayer mp) {
                    counter++;
                    vv1.setVideoPath("android.resource://" + getPackageName() + "/" + data[counter]);
                    vv1.start();
                }

            });
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top