Commit 97ca2a027b74acc9479945c54640a4a5aa6e600a
1 parent
eb47ac60
1 封装视频库
Showing
5 changed files
with
27 additions
and
30 deletions
cloud/video/src/main/java/com/libs/video/video/exoplayer/component/DefaultErrorView.java
cloud/video/src/main/java/com/libs/video/video/exoplayer/model/AdVideoModel.java deleted
100644 → 0
| 1 | -package com.libs.video.video.exoplayer.model; | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * 广告视频 | |
| 5 | - */ | |
| 6 | -public class AdVideoModel { | |
| 7 | - private String playerUrl; | |
| 8 | - private int videoType; | |
| 9 | - | |
| 10 | - public String getPlayerUrl() { | |
| 11 | - return playerUrl; | |
| 12 | - } | |
| 13 | - | |
| 14 | - public void setPlayerUrl(String playerUrl) { | |
| 15 | - this.playerUrl = playerUrl; | |
| 16 | - } | |
| 17 | - | |
| 18 | - public int getVideoType() { | |
| 19 | - return videoType; | |
| 20 | - } | |
| 21 | - | |
| 22 | - public void setVideoType(int videoType) { | |
| 23 | - this.videoType = videoType; | |
| 24 | - } | |
| 25 | -} |
cloud/video/src/main/java/com/libs/video/video/exoplayer/play/AbstractPlayer.java
cloud/video/src/main/java/com/libs/video/video/exoplayer/play/CNVideoView.java
| ... | ... | @@ -60,7 +60,7 @@ public class CNVideoView<P extends AbstractPlayer> extends FrameLayout |
| 60 | 60 | public static final int SCREEN_SCALE_MATCH_PARENT = 3; |
| 61 | 61 | public static final int SCREEN_SCALE_ORIGINAL = 4; |
| 62 | 62 | public static final int SCREEN_SCALE_CENTER_CROP = 5; |
| 63 | - protected int mCurrentScreenScaleType; | |
| 63 | + protected int mCurrentScreenScaleType;//当前视频缩放类型 | |
| 64 | 64 | |
| 65 | 65 | protected int[] mVideoSize = {0, 0}; |
| 66 | 66 | |
| ... | ... | @@ -143,7 +143,9 @@ public class CNVideoView<P extends AbstractPlayer> extends FrameLayout |
| 143 | 143 | mEnableAudioFocus = config.mEnableAudioFocus; |
| 144 | 144 | mProgressManager = config.mProgressManager; |
| 145 | 145 | mPlayerFactory = config.mPlayerFactory; |
| 146 | + //缩放类型 | |
| 146 | 147 | mCurrentScreenScaleType = config.mScreenScaleType; |
| 148 | + //获取当前的渲染器 | |
| 147 | 149 | mRenderViewFactory = config.mRenderViewFactory; |
| 148 | 150 | |
| 149 | 151 | //读取xml中的配置,并综合全局配置 |
| ... | ... | @@ -161,8 +163,11 @@ public class CNVideoView<P extends AbstractPlayer> extends FrameLayout |
| 161 | 163 | * 初始化播放器视图 |
| 162 | 164 | */ |
| 163 | 165 | protected void initView() { |
| 166 | + //创建播放组件承载布局 | |
| 164 | 167 | mPlayerContainer = new FrameLayout(getContext()); |
| 168 | + //设置当前背景颜色 | |
| 165 | 169 | mPlayerContainer.setBackgroundColor(mPlayerBackgroundColor); |
| 170 | + //设置布局参数 | |
| 166 | 171 | LayoutParams params = new LayoutParams( |
| 167 | 172 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 168 | 173 | ViewGroup.LayoutParams.MATCH_PARENT); |
| ... | ... | @@ -567,7 +572,7 @@ public class CNVideoView<P extends AbstractPlayer> extends FrameLayout |
| 567 | 572 | setPlayState(STATE_PLAYBACK_COMPLETED); |
| 568 | 573 | |
| 569 | 574 | if (curentPlayIndex + 1 <= dataSource.size() - 1) { |
| 570 | - curentPlayIndex+=1; | |
| 575 | + curentPlayIndex += 1; | |
| 571 | 576 | mUrl = dataSource.get(curentPlayIndex); |
| 572 | 577 | replay(true); |
| 573 | 578 | } | ... | ... |
cloud/video/src/main/java/com/libs/video/video/exoplayer/playerCore/exoplayer/ExoMediaPlayer.java
| ... | ... | @@ -38,7 +38,9 @@ import java.util.Map; |
| 38 | 38 | public class ExoMediaPlayer extends AbstractPlayer implements VideoListener, Player.EventListener { |
| 39 | 39 | |
| 40 | 40 | protected Context mAppContext; |
| 41 | + //播放器 | |
| 41 | 42 | protected SimpleExoPlayer exoPlayer; |
| 43 | + //播放源 | |
| 42 | 44 | protected MediaSource mMediaSource; |
| 43 | 45 | protected ExoMediaSourceHelper mMediaSourceHelper; |
| 44 | 46 | //播放参数控制 |
| ... | ... | @@ -48,9 +50,11 @@ public class ExoMediaPlayer extends AbstractPlayer implements VideoListener, Pla |
| 48 | 50 | private boolean mLastReportedPlayWhenReady = false; |
| 49 | 51 | private boolean mIsPreparing;//是否准备 |
| 50 | 52 | private boolean mIsBuffering;//是否缓冲 |
| 51 | - | |
| 53 | + //加载控制 | |
| 52 | 54 | private LoadControl mLoadControl; |
| 55 | + //渲染器设置 | |
| 53 | 56 | private RenderersFactory mRenderersFactory; |
| 57 | + //轨道选择 | |
| 54 | 58 | private TrackSelector mTrackSelector; |
| 55 | 59 | |
| 56 | 60 | public ExoMediaPlayer(Context context) { |
| ... | ... | @@ -217,6 +221,9 @@ public class ExoMediaPlayer extends AbstractPlayer implements VideoListener, Pla |
| 217 | 221 | mSpeedPlaybackParameters = null; |
| 218 | 222 | } |
| 219 | 223 | |
| 224 | + /**获取当前的播放进度 | |
| 225 | + * @return | |
| 226 | + */ | |
| 220 | 227 | @Override |
| 221 | 228 | public long getCurrentPosition() { |
| 222 | 229 | if (exoPlayer == null) |
| ... | ... | @@ -357,6 +364,11 @@ public class ExoMediaPlayer extends AbstractPlayer implements VideoListener, Pla |
| 357 | 364 | } |
| 358 | 365 | } |
| 359 | 366 | |
| 367 | + /** | |
| 368 | + * 播放异常 | |
| 369 | + * | |
| 370 | + * @param error | |
| 371 | + */ | |
| 360 | 372 | @Override |
| 361 | 373 | public void onPlayerError(ExoPlaybackException error) { |
| 362 | 374 | if (mPlayerEventListener != null) { |
| ... | ... | @@ -364,6 +376,12 @@ public class ExoMediaPlayer extends AbstractPlayer implements VideoListener, Pla |
| 364 | 376 | } |
| 365 | 377 | } |
| 366 | 378 | |
| 379 | + /**视频大小发生变化 | |
| 380 | + * @param width | |
| 381 | + * @param height | |
| 382 | + * @param unappliedRotationDegrees | |
| 383 | + * @param pixelWidthHeightRatio | |
| 384 | + */ | |
| 367 | 385 | @Override |
| 368 | 386 | public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) { |
| 369 | 387 | if (mPlayerEventListener != null) { | ... | ... |