Android.widget.VideoView
lastmod 2018-08-17created 2016-06-022 edits
Notes on how to use Android android.widget.VideoView.
Simple example
You can play a video simply as follows.
First, add a VideoView to the Layout as below.
<VideoView
android:id="@+id/videoview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
Then insert the code to play the video into the Activity.
VideoView video = (VideoView) findViewById(R.id.videoview);
// 필요하다면 미디어 컨트롤러를 추가할 수 있다.
MediaController mc = new MediaController(this);
mc.setAnchorView(video);
mc.setMediaPlayer(video);
video.setMediaController(mc);
// 재생할 영상 URI를 적용한다.
String path="http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8";
//String path="http://sites.google.com/site/ubiaccessmobile/sample_video.mp4";
//String path="http://video.webmfiles.org/big-buck-bunny_trailer.webm";
Uri uri = Uri.parse(path);
video.setVideoURI(uri);
// 재생.
video.start();
Note that playing a video via a URI uses the Internet, so you must add the permission to the Manifest as below.
Example
How to display a video in a VideoView.
public void setPreviewVideoPath(String path) {
VideoView video = (VideoView) _preview_viewer.findViewById(R.id.createpreview_view__video);
if (video != null) {
_preview_viewer.removeView(video);
_preview_viewer.addView(video, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
video.setVisibility(View.VISIBLE);
video.setZOrderOnTop(true);
video.setVideoPath(path);
// 비디오 컨트롤러연동.
MediaController controller = new MediaController(this);
controller.setAnchorView(video);
// controller.setVisibility(View.INVISIBLE); // 미디어 컨트롤러 HIDE.
video.setMediaController(controller);
_video_preview = video;
}
}
See also
Favorite site
- Android VideoView (playing video attachments)
- Playing Android Video (with VideoView)
- Notes on MediaPlayer background work
- Playing online video on Android
- Stackoverflow: Rotating the actual videobuffer in Videoview
References
-
Android_rotate_videoview.pdf ↩