Monday, July 22, 2013

Android: video playback

summary:
  1. Add VideoView into the xml layout
  2. copy video into "res/raw" folder
  3. import android.widget.VideoView
  4. VideoView videoView;
  5. videoView = (VideoView)this.findViewById(R.id.videoView1);
  6. String path = "android.resource://" + this.getPackageName() + "/" + R.raw.render; // assume that the video is render.mp4
    • alternatively: can use - String path = "android.resource://" + this.getPackageName() + "/raw/render"; // assume video is render.mp4
    • can use http url to a video file online. but must add uses permission to Internet in Manifest.xml - <uses-permission android:name="android.permission.INTERNET"/>
  7. videoView.setVideoPath(path );
  8. videoView.start();

No comments: