We want to play a mp4 file, let copy in to raw folder.
In xml file, create a video view.
<VideoView android:layout_width="wrap_content"
android:id="@+id/video"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
android:keepScreenOn="true"
/>
In class, declare to above Override.
VideoView view;
Import library.
Find andress, initial and play video file below
setContentView.
view =
(VideoView)findViewById(R.id.video);
String path = "android.resource://" +
getPackageName() + "/" + R.raw.abc;
view.setVideoPath(path);
view.start();
view.setMediaController(null);
If want to loop video, use these lines.
view.setOnPreparedListener(new
OnPreparedListener() {
@Override
public void
onPrepared(MediaPlayer mp) {
// TODO
Auto-generated method stub
view.setLooping(true);
}
});
To play other format file, we have to use outside
library.
No comments:
Post a Comment