星空网 > 软件开发 > 操作系统

手机影音6

手机影音6images/loading.gif' data-original="http://images2015.cnblogs.com/blog/1044471/201611/1044471-20161114010847326-633010270.png" >

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

  

  

  

  




原标题:手机影音6

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流