2. Play Video
Warning: You should test a video on a real
Android device. It is terrible on the Emulator.
1. Push a video, e.g. onto sdcard. (See slide
09.2.2)
2. In main.xml, add a VideoView:
<VideoView
android:id="@+id/videoView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
3. • In Java:
public class PlayVideoActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView video = (VideoView)findViewById(R.id.videoView1);
video.setVideoPath("file:///sdcard/Sok Pisey.mp4");
video.setMediaController(new MediaController(this));
video.start();
video.requestFocus();
}
}