Umair Ahmad Ch
Umair Ahmad Ch

Reputation: 11

can't play video in android studio

import android.widget.VideoView;
import android.widget.MediaController;

// to control media i.e; stop, play, pause

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // start coding from here
        final VideoView buckysVideoView = (VideoView) findViewById(R.id.buckysVideoView);
        buckysVideoView.setVideoPath("https://www.thenewboston.com/forum/project_files/006_testVideo.mp4");

        // applying mediaControler properties
        MediaController mediaController = new MediaController(this);
        mediaController.setAnchorView(buckysVideoView);
        buckysVideoView.setMediaController(mediaController);

        buckysVideoView.start();
    }

}

Upvotes: 1

Views: 3365

Answers (1)

meda
meda

Reputation: 45500

Don't use setVideoPath that would be appropriate if the video is stored on your device, you should use setVideoURI for video over http.

String urlStrinh = "https://www.thenewboston.com/forum/project_files/006_testVideo.mp4";
VideoView buckysVideoView = (VideoView) findViewById(R.id.buckysVideoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(buckysVideoView);
Uri videoURI = Uri.parse(urlString);
buckysVideoView.setMediaController(mediaController);
buckysVideoView.setVideoURI(videoURI);
buckysVideoView.start();

Upvotes: 1

Related Questions