Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This recipe shows how to play a video using the VideoView and MediaController.
Follow these steps to play a video:
Add a VideoView to an Main.axml layout.
01.<?xml version="1.0" encoding="utf-8"?> 02.<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 03. android:orientation="vertical" 04. android:layout_width="match_parent" 05. android:layout_height="match_parent"> 06. <android.support.v7.widget.Toolbar 07. android:id="@+id/toolbar" 08. android:layout_width="match_parent" 09. android:layout_height="wrap_content" 10. android:background="#F8F8F8" /> 11. <ListView 12. android:id="@+id/lstView" 13. android:layout_width="match_parent" 14. android:layout_height="match_parent" 15. android:background="@android:color/white" /> 16.</LinearLayout>
Obtain a reference to the VideoView in code.
1.var video_view = FindViewById<VideoView>(Resource.Id.videoView);
Create an Android.Net.Uri for the video.
1.var uri = Android.Net.Uri.Parse ("video url goes here");
Pass this URI to the VideoView.
1.video_view.SetVideoURI (uri);
Create an MediaController for VideoView.
1.private MediaController media_controller;
Set MediaController to the VideoView.
1.media_controller = new Android.Widget.MediaController(this); 2.media_controller.SetMediaPlayer(video_view); 3.video_view.SetMediaController(media_controller); 4.video_view.RequestFocus();
Start the VideoView.
1.video_view.Start();
In AndroidManifest, we set the INTERNET permission and press OK.