Android VideoView local video playback

Source: Internet
Author: User

This article describes how to use VideoView to play a local video. It is relatively simple to use. The MediaController class is added in it to implement more video control functions.

Implementation:


Code;

Layout file:

With VideoView, VideoView is a view with the video playback function, which can be used directly in the layout.

     
  
 

MainActivity:

Package com. multimediademo11videoview; import android. app. activity; import android.net. uri; import android. OS. bundle; import android. OS. environment; import android. widget. mediaController; import android. widget. videoView; public class MainActivity extends Activity {private VideoView videoView; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. la Yout. activity_main); videoView = (VideoView) findViewById (R. id. videoView);/*** VideoView has fewer functions to control video playback. Specifically, it only has the start and pause methods. To provide more control, * You can instantiate a MediaController and set it to the VideoView controller through the setMediaController method. */VideoView. setMediaController (new MediaController (this); Uri videoUri = Uri. parse (Environment. getExternalStorageDirectory (). getPath () + "/1.mp4"); videoView. setVideoURI (videoUri); videoView. start ();}}

Source code download:

Click to download source code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.