Junior Barreto
Junior Barreto

Reputation: 55

Change a video that plays in a VideoView whenever I want. Manually

I have an activity that has a button, when I click this button another activity opens and plays a video defined by me from sdcard (or phone).

The problem: I want to change which video will play always when I wish.

Example: first I pre-define to play a video about Mario. Later, I want that the same button plays a video about Luigi, then I do some method that allow me to make this trade. Or any user that use the app.

Anybody could help me how can I do this?

Here's the basic code:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main); 
    

    video_player = (VideoView) findViewById(R.id.video_frame); 
    media_Controller = new MediaController(this);
    dm = new DisplayMetrics(); 
    this.getWindowManager().getDefaultDisplay().getMetrics(dm);
    int height = dm.heightPixels; 
    int width = dm.widthPixels;
    video_player.setMinimumWidth(width); 
    video_player.setMinimumHeight(height); 
    video_player.setMediaController(media_Controller); 
    video_player.setVideoPath("/sdcard/videoplay.mp4"); 
    video_player.start(); 

}

Upvotes: 0

Views: 1418

Answers (1)

RDY
RDY

Reputation: 683

In button click dynamatically change video url as per your wish store string url. //first activity

Intent intent = new Intent(getActivity(), VideoFullScreenActivity.class);       
    intent.putExtra("URL", url);
    startActivity(intent);

//video activity

if (intent.hasExtra("URL")) {
            urlVideo = intent.getStringExtra("URL");
        }

        video = (VideoView) findViewById(R.id.videoView);

        media = new CustomMediaController(this);
        media.setAnchorView(video);
        video.setMediaController(media);

    video.setVideoURI(Uri.parse(urlVideo));
    video.requestFocus();
    video.seekTo(current);

    video.start();

Upvotes: 1

Related Questions