Commit 97ca2a027b74acc9479945c54640a4a5aa6e600a

Authored by YangShuai
1 parent eb47ac60

1 封装视频库

cloud/video/src/main/java/com/libs/video/video/exoplayer/component/DefaultErrorView.java
@@ -19,7 +19,6 @@ import androidx.annotation.Nullable; @@ -19,7 +19,6 @@ import androidx.annotation.Nullable;
19 19
20 /** 20 /**
21 * 播放出错提示界面 21 * 播放出错提示界面
22 - * Created by dueeeke on 2017/4/13.  
23 */ 22 */
24 public class DefaultErrorView extends LinearLayout implements IControlComponent { 23 public class DefaultErrorView extends LinearLayout implements IControlComponent {
25 24
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
@@ -7,7 +7,7 @@ import android.view.SurfaceHolder; @@ -7,7 +7,7 @@ import android.view.SurfaceHolder;
7 import java.util.Map; 7 import java.util.Map;
8 8
9 /** 9 /**
10 - * 抽象播放器 10 + * 抽象播放器 只定义基本功能,可以选择用哪个播放器实现播放
11 * Created by ShinnyYang 11 * Created by ShinnyYang
12 */ 12 */
13 13
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,7 +60,7 @@ public class CNVideoView<P extends AbstractPlayer> extends FrameLayout
60 public static final int SCREEN_SCALE_MATCH_PARENT = 3; 60 public static final int SCREEN_SCALE_MATCH_PARENT = 3;
61 public static final int SCREEN_SCALE_ORIGINAL = 4; 61 public static final int SCREEN_SCALE_ORIGINAL = 4;
62 public static final int SCREEN_SCALE_CENTER_CROP = 5; 62 public static final int SCREEN_SCALE_CENTER_CROP = 5;
63 - protected int mCurrentScreenScaleType; 63 + protected int mCurrentScreenScaleType;//当前视频缩放类型
64 64
65 protected int[] mVideoSize = {0, 0}; 65 protected int[] mVideoSize = {0, 0};
66 66
@@ -143,7 +143,9 @@ public class CNVideoView<P extends AbstractPlayer> extends FrameLayout @@ -143,7 +143,9 @@ public class CNVideoView<P extends AbstractPlayer> extends FrameLayout
143 mEnableAudioFocus = config.mEnableAudioFocus; 143 mEnableAudioFocus = config.mEnableAudioFocus;
144 mProgressManager = config.mProgressManager; 144 mProgressManager = config.mProgressManager;
145 mPlayerFactory = config.mPlayerFactory; 145 mPlayerFactory = config.mPlayerFactory;
  146 + //缩放类型
146 mCurrentScreenScaleType = config.mScreenScaleType; 147 mCurrentScreenScaleType = config.mScreenScaleType;
  148 + //获取当前的渲染器
147 mRenderViewFactory = config.mRenderViewFactory; 149 mRenderViewFactory = config.mRenderViewFactory;
148 150
149 //读取xml中的配置,并综合全局配置 151 //读取xml中的配置,并综合全局配置
@@ -161,8 +163,11 @@ public class CNVideoView<P extends AbstractPlayer> extends FrameLayout @@ -161,8 +163,11 @@ public class CNVideoView<P extends AbstractPlayer> extends FrameLayout
161 * 初始化播放器视图 163 * 初始化播放器视图
162 */ 164 */
163 protected void initView() { 165 protected void initView() {
  166 + //创建播放组件承载布局
164 mPlayerContainer = new FrameLayout(getContext()); 167 mPlayerContainer = new FrameLayout(getContext());
  168 + //设置当前背景颜色
165 mPlayerContainer.setBackgroundColor(mPlayerBackgroundColor); 169 mPlayerContainer.setBackgroundColor(mPlayerBackgroundColor);
  170 + //设置布局参数
166 LayoutParams params = new LayoutParams( 171 LayoutParams params = new LayoutParams(
167 ViewGroup.LayoutParams.MATCH_PARENT, 172 ViewGroup.LayoutParams.MATCH_PARENT,
168 ViewGroup.LayoutParams.MATCH_PARENT); 173 ViewGroup.LayoutParams.MATCH_PARENT);
@@ -567,7 +572,7 @@ public class CNVideoView<P extends AbstractPlayer> extends FrameLayout @@ -567,7 +572,7 @@ public class CNVideoView<P extends AbstractPlayer> extends FrameLayout
567 setPlayState(STATE_PLAYBACK_COMPLETED); 572 setPlayState(STATE_PLAYBACK_COMPLETED);
568 573
569 if (curentPlayIndex + 1 <= dataSource.size() - 1) { 574 if (curentPlayIndex + 1 <= dataSource.size() - 1) {
570 - curentPlayIndex+=1; 575 + curentPlayIndex += 1;
571 mUrl = dataSource.get(curentPlayIndex); 576 mUrl = dataSource.get(curentPlayIndex);
572 replay(true); 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,7 +38,9 @@ import java.util.Map;
38 public class ExoMediaPlayer extends AbstractPlayer implements VideoListener, Player.EventListener { 38 public class ExoMediaPlayer extends AbstractPlayer implements VideoListener, Player.EventListener {
39 39
40 protected Context mAppContext; 40 protected Context mAppContext;
  41 + //播放器
41 protected SimpleExoPlayer exoPlayer; 42 protected SimpleExoPlayer exoPlayer;
  43 + //播放源
42 protected MediaSource mMediaSource; 44 protected MediaSource mMediaSource;
43 protected ExoMediaSourceHelper mMediaSourceHelper; 45 protected ExoMediaSourceHelper mMediaSourceHelper;
44 //播放参数控制 46 //播放参数控制
@@ -48,9 +50,11 @@ public class ExoMediaPlayer extends AbstractPlayer implements VideoListener, Pla @@ -48,9 +50,11 @@ public class ExoMediaPlayer extends AbstractPlayer implements VideoListener, Pla
48 private boolean mLastReportedPlayWhenReady = false; 50 private boolean mLastReportedPlayWhenReady = false;
49 private boolean mIsPreparing;//是否准备 51 private boolean mIsPreparing;//是否准备
50 private boolean mIsBuffering;//是否缓冲 52 private boolean mIsBuffering;//是否缓冲
51 - 53 + //加载控制
52 private LoadControl mLoadControl; 54 private LoadControl mLoadControl;
  55 + //渲染器设置
53 private RenderersFactory mRenderersFactory; 56 private RenderersFactory mRenderersFactory;
  57 + //轨道选择
54 private TrackSelector mTrackSelector; 58 private TrackSelector mTrackSelector;
55 59
56 public ExoMediaPlayer(Context context) { 60 public ExoMediaPlayer(Context context) {
@@ -217,6 +221,9 @@ public class ExoMediaPlayer extends AbstractPlayer implements VideoListener, Pla @@ -217,6 +221,9 @@ public class ExoMediaPlayer extends AbstractPlayer implements VideoListener, Pla
217 mSpeedPlaybackParameters = null; 221 mSpeedPlaybackParameters = null;
218 } 222 }
219 223
  224 + /**获取当前的播放进度
  225 + * @return
  226 + */
220 @Override 227 @Override
221 public long getCurrentPosition() { 228 public long getCurrentPosition() {
222 if (exoPlayer == null) 229 if (exoPlayer == null)
@@ -357,6 +364,11 @@ public class ExoMediaPlayer extends AbstractPlayer implements VideoListener, Pla @@ -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 @Override 372 @Override
361 public void onPlayerError(ExoPlaybackException error) { 373 public void onPlayerError(ExoPlaybackException error) {
362 if (mPlayerEventListener != null) { 374 if (mPlayerEventListener != null) {
@@ -364,6 +376,12 @@ public class ExoMediaPlayer extends AbstractPlayer implements VideoListener, Pla @@ -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 @Override 385 @Override
368 public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) { 386 public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) {
369 if (mPlayerEventListener != null) { 387 if (mPlayerEventListener != null) {