Play videos in Android

Source: Internet
Author: User
Package com. king. android. media;

Import java. io. File;
Import java. io. FilenameFilter;

Import android. app. Activity;
Import android. OS. Bundle;
Import android. view. View;
Import android. view. View. OnClickListener;
Import android. widget. Button;
Import android. widget. MediaController;
Import android. widget. VideoView;

Import com. king. android. R;

/**

* Description: video playback.
* Author: Andy. Liu
* Time: 08:36:20
**/
Public class VideoActivity extends Activity implements OnClickListener {
Public static final String FILE_END_NAME = ". mp4 ";
Public static final String path = "/sdcard/videotest.mp4 ";
VideoView videoView;
@ Override
Protected void onCreate (Bundle savedInstanceState ){

Super. onCreate (savedInstanceState );

SetContentView (R. layout. video_layout );

VideoView = (VideoView) findViewById (R. id. vv_videoView );

Button btnOperate = (Button) findViewById (R. id. btn_load );
BtnOperate. setOnClickListener (this );

BtnOperate = (Button) findViewById (R. id. btn_pause );
BtnOperate. setOnClickListener (this );

BtnOperate = (Button) findViewById (R. id. btn_play );
BtnOperate. setOnClickListener (this );

/* Three buttons for Operation playback */

}

@ Override
Public void onClick (View v ){
Switch (v. getId ()){
Case R. id. btn_load:
// Set the path
VideoView. setVideoPath (path );
// Set the mode-Playback progress bar
VideoView. setMediaController (new MediaController (VideoActivity. this ));
VideoView. requestFocus (); // get the focus
Break;

Case R. id. btn_pause:
VideoView. pause ();
Break;

Case R. id. btn_play:
VideoView. start ();
Break;
}
}

Class VideoFilter implements FilenameFilter {

@ Override
Public boolean accept (File dir, String filename ){

Return (filename. endsWith (FILE_END_NAME ));
}

}

}

 

ViewVideo control is a method, but surfaceView control can also be used, but this is troublesome and will be studied later...

Related Article

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.