diff --git a/video/src/main/java/com/yunbao/video/views/VideoPlayViewHolder.java b/video/src/main/java/com/yunbao/video/views/VideoPlayViewHolder.java index 86669a0..a14cfb8 100644 --- a/video/src/main/java/com/yunbao/video/views/VideoPlayViewHolder.java +++ b/video/src/main/java/com/yunbao/video/views/VideoPlayViewHolder.java @@ -15,6 +15,7 @@ import com.google.android.exoplayer2.PlaybackException; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; import com.google.android.exoplayer2.ui.StyledPlayerView; +import com.google.android.exoplayer2.video.VideoSize; import com.yunbao.common.bean.ActiveBean; import com.yunbao.common.utils.L; import com.yunbao.common.utils.ToastUtil; @@ -57,14 +58,7 @@ public class VideoPlayViewHolder extends AbsViewHolder implements View.OnClickLi } private void intiPlayView() { - DefaultLoadControl control = new DefaultLoadControl.Builder() - .setPrioritizeTimeOverSizeThresholds(false) - .setBackBuffer(10_000, true) - .setBufferDurationsMs(500, - 5_000, - 150, - 200) - .build(); + DefaultLoadControl control = new DefaultLoadControl.Builder().setPrioritizeTimeOverSizeThresholds(false).setBackBuffer(10_000, true).setBufferDurationsMs(500, 5_000, 150, 200).build(); mPlayer = new ExoPlayer.Builder(mContext).setLoadControl(control).build(); placeholderView = findViewById(com.yunbao.live.R.id.placeholderView); mPlayer = new ExoPlayer.Builder(mContext).setLoadControl(control).build(); @@ -87,10 +81,22 @@ public class VideoPlayViewHolder extends AbsViewHolder implements View.OnClickLi case Player.STATE_ENDED://播放器完整播放了所有媒体。 replay(); break; - } } + @Override + public void onVideoSizeChanged(VideoSize videoSize) { + Player.Listener.super.onVideoSizeChanged(videoSize); + if (mActionListener != null) { + mActionListener.onVideoSize(videoSize.height, videoSize.width); + } + } + + @Override + public void onRenderedFirstFrame() { + Player.Listener.super.onRenderedFirstFrame(); + } + @Override public void onPlayerError(PlaybackException error) { Player.Listener.super.onPlayerError(error); @@ -259,6 +265,8 @@ public class VideoPlayViewHolder extends AbsViewHolder implements View.OnClickLi void onFirstFrame(); + void onVideoSize(int height, int width); + void onProgress(int progress, int duration); } diff --git a/video/src/main/java/com/yunbao/video/views/VideoPlayWrapViewHolder.java b/video/src/main/java/com/yunbao/video/views/VideoPlayWrapViewHolder.java index 0d6ffc6..daa73df 100644 --- a/video/src/main/java/com/yunbao/video/views/VideoPlayWrapViewHolder.java +++ b/video/src/main/java/com/yunbao/video/views/VideoPlayWrapViewHolder.java @@ -57,7 +57,7 @@ import java.util.List; public class VideoPlayWrapViewHolder extends AbsViewHolder implements View.OnClickListener { private ViewGroup mVideoContainer; - private MyImageView mCover; + private ImageView mCover; private ImageView mAvatar; private TextView mName; private TextView mTitle; @@ -101,7 +101,7 @@ public class VideoPlayWrapViewHolder extends AbsViewHolder implements View.OnCli progressCount = (TextView) findViewById(R.id.progressCount); mVideoContainer = (ViewGroup) findViewById(R.id.video_container); - mCover = (MyImageView) findViewById(R.id.cover); + mCover = (ImageView) findViewById(R.id.cover); mAvatar = (ImageView) findViewById(R.id.avatar); mName = (TextView) findViewById(R.id.name); mTitle = (TextView) findViewById(R.id.title); @@ -303,20 +303,6 @@ public class VideoPlayWrapViewHolder extends AbsViewHolder implements View.OnCli mCover.requestLayout(); } mCover.setImageDrawable(drawable); - - /* - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); - - int imageWidth = drawable.getIntrinsicWidth(); - int imageHeight = drawable.getIntrinsicHeight(); - - //宽度固定,然后根据原始宽高比得到此固定宽度需要的高度 - //screenWidth 是屏幕宽度 - int height = mCover.getWidth() * imageHeight / imageWidth; - ViewGroup.LayoutParams para = mCover.getLayoutParams(); - para.height = height; - para.width = mCover.getWidth();*/ - //mCover.setImageDrawable(drawable); } } @@ -367,6 +353,15 @@ public class VideoPlayWrapViewHolder extends AbsViewHolder implements View.OnCli } } + public void onSetVideoCoverSize(int height, int width) { + if (mCover != null) { + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mCover.getLayoutParams(); + params.width = width; + params.height = height; + } + } + + /** * 滑出屏幕 */ @@ -529,20 +524,7 @@ public class VideoPlayWrapViewHolder extends AbsViewHolder implements View.OnCli } else { image = mVideoBean.getVideo() + "?vframe/jpg/offset/0"; } - new SharePopDialog(mContext) - .setShareType(SharePopDialog.TYPE_VIDEO) - .setShareData(ShareBean.ShareBuilder.create() - .setShareType(SharePopDialog.TYPE_VIDEO) - .setUid(CommonAppConfig.getInstance().getUid()) - .setCover(StringUtil.isEmpty(image) ? mVideoBean.getUser_avatar() : image) - .setTitle(StringUtil.isEmpty(mVideoBean.getContent()) ? mVideoBean.getUser_name() : JSONObject.parseObject(mVideoBean.getContent()).getString("msg")) - .setAnchorId(mVideoBean.getUser_id()) - .setAnchorName(mVideoBean.getUser_name()) - .setAnchorAvatar(mVideoBean.getUser_avatar()) - .setExtraData(mVideoBean.getId()) - .build() - ) - .showDialog(); + new SharePopDialog(mContext).setShareType(SharePopDialog.TYPE_VIDEO).setShareData(ShareBean.ShareBuilder.create().setShareType(SharePopDialog.TYPE_VIDEO).setUid(CommonAppConfig.getInstance().getUid()).setCover(StringUtil.isEmpty(image) ? mVideoBean.getUser_avatar() : image).setTitle(StringUtil.isEmpty(mVideoBean.getContent()) ? mVideoBean.getUser_name() : JSONObject.parseObject(mVideoBean.getContent()).getString("msg")).setAnchorId(mVideoBean.getUser_id()).setAnchorName(mVideoBean.getUser_name()).setAnchorAvatar(mVideoBean.getUser_avatar()).setExtraData(mVideoBean.getId()).build()).showDialog(); } public void release() { diff --git a/video/src/main/java/com/yunbao/video/views/VideoScrollViewHolder.java b/video/src/main/java/com/yunbao/video/views/VideoScrollViewHolder.java index b697cf3..60d8010 100644 --- a/video/src/main/java/com/yunbao/video/views/VideoScrollViewHolder.java +++ b/video/src/main/java/com/yunbao/video/views/VideoScrollViewHolder.java @@ -241,6 +241,13 @@ public class VideoScrollViewHolder extends AbsViewHolder implements VideoScrollA } } + @Override + public void onVideoSize(int height, int width) { + if (mVideoPlayWrapViewHolder != null) { + mVideoPlayWrapViewHolder.onSetVideoCoverSize(height, width); + } + } + @Override public void onProgress(int progress, int duration) { if (mVideoPlayWrapViewHolder != null) { @@ -318,7 +325,7 @@ public class VideoScrollViewHolder extends AbsViewHolder implements VideoScrollA */ private void openCommentInputWindow(boolean openFace) { if (mVideoBean != null) { - ((AbsVideoPlayActivity) mContext).openCommentInputWindowNew(openFace, mVideoBean.getId(), mVideoBean.getUser_id(), false,"",Integer.parseInt(mVideoBean.getComment_num())); + ((AbsVideoPlayActivity) mContext).openCommentInputWindowNew(openFace, mVideoBean.getId(), mVideoBean.getUser_id(), false, "", Integer.parseInt(mVideoBean.getComment_num())); } } diff --git a/video/src/main/res/layout/view_video_play_wrap.xml b/video/src/main/res/layout/view_video_play_wrap.xml index 5c6e171..7f55226 100644 --- a/video/src/main/res/layout/view_video_play_wrap.xml +++ b/video/src/main/res/layout/view_video_play_wrap.xml @@ -10,11 +10,13 @@ android:layout_width="match_parent" android:layout_height="match_parent" /> - + android:layout_centerHorizontal="true" + android:layout_centerVertical="true" + android:scaleType="centerCrop" />