As the final recipe of this chapter, we will see how to play a movie with your Android application. Playing video, unlike playing audio, involves some special View
elements for displaying it to the users.
For the last time, we will reuse the same project, and more specifically, we will play a video of Mario under the button for playing the Mario theme seen in the previous recipe.
Main.axml
file under the Layout
file:<VideoView android:id="@+id/myVideoView" android:layout_width="fill_parent" android:layout_height="fill_parent"> </VideoView>
Main.axml
file should look as follows:MainActivity.cs
class in the OnCreate()
method:var videoView = FindViewById<VideoView> (Resource.Id.SampleVideoView); var uri = Android.Net.Uri.Parse ("url of your video"); videoView.SetVideoURI (uri);
videoView.Start();
method.As discussed in the introduction to this recipe, playing a video should involve a special view to display it to users. This special view is named the VideoView
element and should be used in the same way as the simple TextView
element that we saw earlier in this book:
<VideoView android:id="@+id/myVideoView" android:layout_width="fill_parent" android:layout_height="fill_parent"> </VideoView>
As you can see in the previous code sample, you can apply the same parameters to the VideoView
element as the TextView
element, such as layout-based options.
The VideoView
element, like the MediaPlayer
class for audio, has a method to set the video URI, named SetVideoURI
, and another one to start the video, named Start()
.
Chapter 10, Taking Advantage of the Android Platform, will expand on what you learned here about playing a video, notably by demonstrating how to use the camera and record video.
18.117.138.104