Skip to content

Commit

Permalink
增加了全屏显示的支持 (2017-04-28)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarGuo committed Apr 28, 2017
1 parent 5a5f190 commit 15f9a3b
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 22 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ dependencies {
### 1.6.5(未发布)
* 修改了循环播放的UI问题
* 修改了本地文件或者已缓存文件,显示进度问题
* GSYVideoType增加SCREEN_TYPE_FULL类型,通过按照比例裁减放大视频,达到全屏


### 1.6.4(2017-04-20)
Expand Down
1 change: 1 addition & 0 deletions UPDATE_VERSION.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### 1.6.5(未发布)
* 修改了循环播放的UI问题
* 修改了本地文件或者已缓存文件,显示进度问题
* GSYVideoType增加SCREEN_TYPE_FULL类型,通过按照比例裁减放大视频,达到全屏

### 1.6.4(2017-04-20)
* update ijk to 0.7.9 (增加了soundTouch,调速后声音变调问题得到解决)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private void init() {
//设置旋转
orientationUtils = new OrientationUtils(this, videoPlayer);

//设置全屏按键功能
//设置全屏按键功能,这是使用的是选择屏幕,而不是全屏
videoPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.shuyu.gsyvideoplayer.GSYVideoPlayer;
import com.shuyu.gsyvideoplayer.utils.GSYVideoType;
import com.shuyu.gsyvideoplayer.video.GSYBaseVideoPlayer;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

import java.io.File;
Expand All @@ -30,6 +31,9 @@

/**
* Created by shuyu on 2016/12/7.
* 注意
* 这个播放器的demo配置切换到全屏播放器
* 这只是单纯的作为全屏播放显示,如果需要做大小屏幕切换,请记得在这里耶设置上视频全屏的需要的自定义配置
*/

public class SampleVideo extends StandardGSYVideoPlayer {
Expand Down Expand Up @@ -91,6 +95,12 @@ public void onClick(View v) {
if (mTextureView != null)
mTextureView.requestLayout();
} else if (mType == 2) {
mType = 3;
mMoreScale.setText("全屏");
GSYVideoType.setShowType(GSYVideoType.SCREEN_TYPE_FULL);
if (mTextureView != null)
mTextureView.requestLayout();
} else if (mType == 3) {
mType = 0;
mMoreScale.setText("默认比例");
GSYVideoType.setShowType(GSYVideoType.SCREEN_TYPE_DEFAULT);
Expand Down Expand Up @@ -162,6 +172,16 @@ public int getLayoutId() {
return R.layout.sample_video;
}


@Override
public GSYBaseVideoPlayer startWindowFullscreen(Context context, boolean actionBar, boolean statusBar) {
SampleVideo sampleVideo = (SampleVideo) super.startWindowFullscreen(context, actionBar, statusBar);
//这个播放器的demo配置切换到全屏播放器
//这只是单纯的作为全屏播放显示,如果需要做大小屏幕切换,请记得在这里耶设置上视频全屏的需要的自定义配置
//可参考super中的实现
return sampleVideo;
}

/**
* 弹出切换清晰度
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.shuyu.gsyvideoplayer;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
Expand All @@ -10,8 +11,14 @@
* Created by shuyu on 2016/12/6.
*/

@SuppressLint("AppCompatCustomView")
public class GSYImageCover extends ImageView {


private boolean fullView;

private int originW, originH;

public GSYImageCover(Context context, AttributeSet attrs) {
super(context, attrs);
}
Expand All @@ -37,8 +44,11 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthS = getDefaultSize(videoWidth, widthMeasureSpec);
int heightS = getDefaultSize(videoHeight, heightMeasureSpec);

///Debuger.printfError("******** video size " + getRotation() + " " + videoHeight + " *****1 " + videoWidth);
//Debuger.printfError("******** widget size " + widthS + " *****2 " + heightS);
if (originW == 0 || originH == 0) {
originW = widthS;
originH = heightS;
}

if (videoWidth > 0 && videoHeight > 0) {

int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
Expand Down Expand Up @@ -83,9 +93,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// no size yet, just adopt the given spec sizes
}

//Debuger.printfError("******** rotate before " + width + " *****3 " + height);

if (getRotation() != 0 && getRotation() % 90 == 0 && Math.abs(getRotation()) != 180) {
boolean rotate = (getRotation() != 0 && getRotation() % 90 == 0 && Math.abs(getRotation()) != 180);
if (rotate) {
if (widthS < heightS) {
if (width > height) {
width = (int) (width * (float) widthS / height);
Expand All @@ -104,7 +113,6 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
}
}

//Debuger.printfError("******** real size before " + width + " *****3 " + height);
//如果旋转后的高度大于宽度
if (width > height) {
//如果视频的旋转后,width(高度)大于控件高度,需要压缩下高度
Expand All @@ -128,7 +136,6 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
}
}

//Debuger.printfError("******** real size " + width + " *****3 " + height);
//如果设置了比例
if (GSYVideoType.getShowType() == GSYVideoType.SCREEN_TYPE_16_9) {
if (height > width) {
Expand All @@ -143,6 +150,50 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
height = width * 3 / 4;
}
}

fullView = (GSYVideoType.getShowType() == GSYVideoType.SCREEN_TYPE_FULL);

//上面会调整一变全屏,这里如果要全屏裁减,就整另外一边
if (fullView) {
if (rotate && getRotation() != 0) {
if (width > height) {
if (height < originW) {
width = (int) (width * ((float) originW / height));
height = originW;
} else if (width < originH) {
height = (int) (height * ((float) originH / width));
width = originH;
}
} else {
if (width < originH) {
height = (int) (height * ((float) originH / width));
width = originH;
} else if (height < originW) {
width = (int) (width * ((float) originW / height));
height = originW;
}
}
} else {
if (height > width) {
if (width < widthS) {
height = (int) (height * ((float) widthS / width));
width = widthS;
} else {
width = (int) (width * ((float) heightS / height));
height = heightS;
}
} else {
if (height < heightS) {
width = (int) (width * ((float) heightS / height));
height = heightS;
} else {
height = (int) (height * ((float) widthS / width));
width = widthS;
}
}
}
}

setMeasuredDimension(width, height);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
originH = heightS;
}

///Debuger.printfError("******** video size " + getRotation() + " " + videoHeight + " *****1 " + videoWidth);
//Debuger.printfError("******** widget size " + widthS + " *****2 " + heightS);
if (videoWidth > 0 && videoHeight > 0) {

int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
Expand Down Expand Up @@ -93,7 +91,6 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// no size yet, just adopt the given spec sizes
}

//Debuger.printfError("******** rotate before " + width + " *****3 " + height);
boolean rotate = (getRotation() != 0 && getRotation() % 90 == 0 && Math.abs(getRotation()) != 180);
if (rotate) {
if (widthS < heightS) {
Expand All @@ -114,7 +111,6 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
}
}

//Debuger.printfError("******** real size before " + width + " *****3 " + height);
//如果旋转后的高度大于宽度
if (width > height) {
//如果视频的旋转后,width(高度)大于控件高度,需要压缩下高度
Expand All @@ -138,7 +134,6 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
}
}

//Debuger.printfError("******** real size " + width + " *****3 " + height);
//如果设置了比例
if (GSYVideoType.getShowType() == GSYVideoType.SCREEN_TYPE_16_9) {
if (height > width) {
Expand All @@ -154,8 +149,10 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
}
}

fullView = (GSYVideoType.getShowType() == GSYVideoType.SCREEN_TYPE_FULL);

//上面会调整一变全屏,这里如果要全屏裁减,就整另外一边
if (true) {
if (fullView) {
if (rotate && getRotation() != 0) {
if (width > height) {
if (height < originW) {
Expand Down Expand Up @@ -209,12 +206,4 @@ public int getSizeH() {
public int getSizeW() {
return sizeW;
}

public boolean isFullView() {
return fullView;
}

public void setFullView(boolean fullView) {
this.fullView = fullView;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class GSYVideoType {
//4:3
public final static int SCREEN_TYPE_4_3 = 2;

//全屏裁减显示
public final static int SCREEN_TYPE_FULL = 4;


public final static int IJKPLAYER = 0;

Expand Down

0 comments on commit 15f9a3b

Please sign in to comment.