你的位置:首页 > 操作系统

[操作系统]手机影音6


1.自定义VideoView

1_自定义VideoView-增加设置视频大小方法

public class VideoView extends android.widget.VideoView {  /**   * Android系统在更加

2_得到屏幕高和宽方法

在播放器中

wm = (WindowManager) getSystemService(WINDOW_SERVICE);screenWidth = wm.getDefaultDisplay().getWidth();screenHeight = wm.getDefaultDisplay().getHeight();DisplayMetrics displayMetrics = new DisplayMetrics();this.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);screenWidth = displayMetrics.widthPixels;screenHeight = displayMetrics.heightPixels;

3_视频默认和全屏  

一播放起来,在准备好了中设置视频播放默认

/** * true全屏 * flase默认*/private boolean isFullScreen = false;/** * 视频全屏和默认 * @param type*/public void setVideoType(int type){	switch (type) {		case SCREEN_FULL:			videoview.setVideoSize(screenWidth, screenHeight);			isFullScreen = true;			btn_switch_screen.setBackgroundResource(R.drawable.btn_screen_dafult_selector);			break;		case SCREEN_DEFULT:			//视频的宽			int mVideoWidth = videoWidth;			//视频的高			int mVideoHeight = videoHeight;			//屏幕的宽			int width = screenWidth;			//屏幕的宽			int height = screenHeight;			if (mVideoWidth > 0 && mVideoHeight > 0) {				if ( mVideoWidth * height > width * mVideoHeight ) {					//Log.i("@@@", "image too tall, correcting");					height = width * mVideoHeight / mVideoWidth;				} else if ( mVideoWidth * height < width * mVideoHeight ) {					//Log.i("@@@", "image too wide, correcting");					width = height * mVideoWidth / mVideoHeight;				} else {					//Log.i("@@@", "aspect ratio is correct: " +					//width+"/"+height+"="+					//mVideoWidth+"/"+mVideoHeight);				}			}			videoview.setVideoSize(width, height);			btn_switch_screen.setBackgroundResource(R.drawable.btn_screen_full_selector);			isFullScreen = false;						break;  }}

4_屏幕保持不锁屏

//设置屏幕不锁屏getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

5_点击按钮的时候实现切换播放模式

case R.id.btn_switch_screen:	if(isFullScreen){	  setVideoType(SCREEN_DEFUALT);	}else{	  setVideoType(SCREEN_FULL);	}break