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;
/**
* 描述:视频播放
* 作者:Andy.Liu
* 时间: 2012-7-25 上午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);
/*操作播放的三个按键*/
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.btn_load:
//设置路径
videoView.setVideoPath(path);
//设置模式-播放进度条
videoView.setMediaController(new MediaController(VideoActivity.this));
videoView.requestFocus(); //获取焦点
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));
}
}
}
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;
/**
* 描述:视频播放
* 作者:Andy.Liu
* 时间: 2012-7-25 上午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);
/*操作播放的三个按键*/
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.btn_load:
//设置路径
videoView.setVideoPath(path);
//设置模式-播放进度条
videoView.setMediaController(new MediaController(VideoActivity.this));
videoView.requestFocus(); //获取焦点
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控件是一种办法,但也可以使用surfaceView控件,但这个比较麻烦,后续研究。。。