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...