Java 代码
public class MVActivity extends Activity implements SurfaceHolder.Callback,
OnBufferingUpdateListener, OnCompletionListener, OnPreparedListener {
private Button mv_finish;
SurfaceView mv_play;
SurfaceHolder surfaceHolder;
MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mv);
mp = MediaPlayer.create(getApplicationContext(), R.raw.sw);//获取raw下的视频文件
mv_play = (SurfaceView) findViewById(R.id.mv_play);
mv_finish = (Button) findViewById(R.id.mv_finish);
surfaceHolder = mv_play.getHolder(); // SurfaceHolder是SurfaceView的控制接口
surfaceHolder.addCallback(this);// 因为这个类实现了SurfaceHolder.Callback接口,所以回调参数直接this
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mv_finish.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();