# VideoView

We wanted to show the various exercises in a video that everyone could replicate. We did not want to implement a YouTube function because we wanted to have our own videos rather than relying on YouTube. To begin, we need an empty activity file, which you can create using the Android Studio IDE. Then, navigate to the XML file you just created and the go-to widgets, and add the VideoView element.

![VideoView](..\assets\VideoViewWidget.png)

If you drag that into your activity, you can change the layout, but it will not function directly. To make it play videos, we need to write some Java code first. 
```java
        VideoView videoView = findViewById(R.id.videoView);
        videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.videofile));
```
replace the video file with the name of the video. Then you need to code the media player aswell.
```java
        MediaController mediaController = new MediaController(this);
        videoView.setMediaController(mediaController);
        videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                videoView.start(); // Restart video on completion
            }
        });`
```
Because we have short videos, we will have an auto replay function.