VideoActivity2

package com.media;

import android.app.Activity;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;

public class VideoActivity2 extends Activity{
  private TextView mTextView01;
  private VideoView mVideoView01;
  private String strVideoPath = "";
  private MediaController controller;
 
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
   
    /* 全屏幕 */
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
      WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.video2);
   
    mTextView01 = (TextView)findViewById(R.id.video2_TextView1);
    mVideoView01 = (VideoView)findViewById(R.id.video2_VideoView);
   
    mVideoView01.setOnPreparedListener(new MediaPlayer.OnPreparedListener(){
      @Override
      public void onPrepared(MediaPlayer mp){
        mTextView01.setText(strVideoPath);
      }
    });
   
    mVideoView01.setOnCompletionListener(new MediaPlayer.OnCompletionListener(){
      @Override
      public void onCompletion(MediaPlayer arg0){
        mMakeTextToast("视频播放完成!",true);
      }
    });
   
   
   
    strVideoPath = "file:///sdcard/maidou.3gp";
    playVideo(strVideoPath);
   
  }
  private void playVideo(String strPath){
    if(strPath!=""){
    
      controller=new MediaController(VideoActivity2.this);
      controller.show(0);
      /* 设定控制Bar显示于否Context中 */
      mVideoView01.setMediaController(controller);
      /* 调用VideoURI方法,指定解析路径 */
      mVideoView01.setVideoURI(Uri.parse(strPath));
      /* 调用VideoView.start()自动播放 */
      mVideoView01.start();
     
    
    }
  }
 
  public void mMakeTextToast(String str, boolean isLong)
  {
    if(isLong==true){
      Toast.makeText(VideoActivity2.this, str, Toast.LENGTH_LONG).show();
    }
    else{
      Toast.makeText(VideoActivity2.this, str, Toast.LENGTH_SHORT).show();
    }
  }
}

 

你可能感兴趣的:(VideoActivity2)