My Java Code and I know How To Play / Stop / Pause Video

videoView=(VideoView)findViewById(R.id.videoView);
// Video from raw Folder 

mediaController = new MediaController(this);
uri = Uri.parse("android.resource://" + getPackageName() + "/"+ R.raw.abc);
videoView.setVideoURI(uri);
mediaController.setMediaPlayer(videoView);
videoView.setMediaController(mediaController);
videoView.requestFocus();
videoView.start();
3

There are 3 answers

1
Suman Dey On BEST ANSWER

Check the videoView state like:

if(videoView.isPlaying()){
 Toast.makeText(context, "Paused", Toast.LENGTH_SHORT).show();
}
1
Galax On

If you know how to pause / start / stop you just need to add a toast in your onClickListener for each button, if, however, you don't really know how to do that here is a simple example

in your layout XML containing the Buttons

<Button
            android:id="@+id/Start"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="onClick" />

<Button
                android:id="@+id/Stop"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:onClick="onClick" />

Then, in your java activity you need to create the defined "onClick" method to handle the click

public void onClick(View view){
    int id = view.getId();

    if(id == R.id.Start){
        Toast.makeText(getApplicationContext(), "Start", Toast.LENGTH_SHORT).show();
    }

    else if(id == R.id.Stop){
        Toast.makeText(getApplicationContext(), "Stop", Toast.LENGTH_SHORT).show();
    }
}
5
AlexWalterbos On

You can extend your VideoView in which you can override pause() and start():

MediaController mediaController = //Setup of your MediaController
mediaController.setMediaPlayer(CustomVideoView);

where your CustomVideoView looks something like this:

public class CustomVideoView extends VideoView {
   @Override
   public void start() {
       super.start();
       Toast.makeText(getContext, "This is your text", Toast.LENGTH_SHORT).show();
   }

   @Override
   public void pause() {
       super.pause();
       Toast.makeText(getContext, "This is your text", Toast.LENGTH_SHORT).show();
   }
}