README.md 7.6 KB
Newer Older
S
shuyu 已提交
1
<h4>基于IJKPlayer的播放器,直接参考了<a href="https://github.com/lipangit/JieCaoVideoPlayer">JieCaoVideoPlayer</a>进行了一些自己想要的调整</h4>
S
shuyu 已提交
2
======================
S
readme  
shuyu 已提交
3
```
S
shuyu 已提交
4 5 6
<dependency>
  <groupId>com.shuyu</groupId>
  <artifactId>gsyVideoPlayer</artifactId>
S
1.1.3  
shuyu 已提交
7
  <version>1.1.3</version>
S
shuyu 已提交
8 9
  <type>pom</type>
</dependency>
S
readme  
shuyu 已提交
10
```
S
readme  
shuyu 已提交
11
```
S
readme  
shuyu 已提交
12

S
1.1.3  
shuyu 已提交
13
compile 'com.shuyu:gsyVideoPlayer:1.1.3'
S
readme  
shuyu 已提交
14

S
readme  
shuyu 已提交
15
```
S
shuyu 已提交
16 17

* <h4>支持基本的拖动,声音、亮度调节</h4>
S
shuyu 已提交
18
* <h4>支持边播边缓存,使用了<a href="https://github.com/danikula/AndroidVideoCache">AndroidVideoCache</a>的代理模式实现</h4>
S
shuyu 已提交
19 20 21 22 23 24
* <h4>支持视频本身自带rotation的旋转</h4>
* <h4>增加了重力旋转与手动旋转的同步支持</h4>
* <h4>支持列表播放</h4>
* <h4>直接添加控件为封面</h4>
* <h4>兼容一些5.0的过场效果</h4>

S
shuyu 已提交
25
## 效果,录屏下的屏幕旋转和实际有些出入
S
fix img  
shuyu 已提交
26 27 28
<img src="https://github.com/CarGuo/GSYVideoPlayer/blob/master/01.jpg" width="218px" height="120px"/>
<img src="https://github.com/CarGuo/GSYVideoPlayer/blob/master/02.jpg" width="120px" height="218px"/>
<img src="https://github.com/CarGuo/GSYVideoPlayer/blob/master/03.jpg" width="120px" height="218px"/>
S
fix img  
shuyu 已提交
29
<p></p>
S
shuyu 已提交
30
* <h4>1、打开一个播放</h4>
S
shuyu 已提交
31 32
<img src="https://github.com/CarGuo/GSYVideoPlayer/blob/master/01.gif" width="240px" height="426px"/>
<img src="https://github.com/CarGuo/GSYVideoPlayer/blob/master/02.gif" width="240px" height="426px"/>
S
shuyu 已提交
33
* <h4>2、列表</h4>
S
shuyu 已提交
34
<img src="https://github.com/CarGuo/GSYVideoPlayer/blob/master/03.gif" width="240px" height="426px"/>
S
shuyu 已提交
35
* <h4>3、详情模式</h4>
S
shuyu 已提交
36 37
<img src="https://github.com/CarGuo/GSYVideoPlayer/blob/master/04.gif" width="240px" height="426px"/>

S
1.1.3  
shuyu 已提交
38 39 40 41 42 43
## 1.1.3
* 优化了第一种列表的全屏动画,5.0以上展开和返回过渡顺畅,支持自动旋转的开启与关闭

* GIF 效果
<img src="https://github.com/CarGuo/GSYVideoPlayer/blob/master/0034.gif" width="240px" height="426px"/>

S
shuyu 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
## 1.1.2
* 增加了TAG和position来实现第一种list列表(非ListVideoUtil模式的列表实现)的滑动错位问题

```

videoList.setOnScrollListener(new AbsListView.OnScrollListener() {
    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
    }

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        int lastVisibleItem = firstVisibleItem + visibleItemCount;
        //大于0说明有播放
        if (GSYVideoManager.instance().getPlayPosition() >= 0) {
            //当前播放的位置
            int position = GSYVideoManager.instance().getPlayPosition();
            //对应的播放列表TAG
            if (GSYVideoManager.instance().getPlayTag().equals(ListNormalAdapter.TAG)
                    && (position < firstVisibleItem || position > lastVisibleItem)) {
                //如果滑出去了上面和下面就是否,和今日头条一样
                GSYVideoPlayer.releaseAllVideos();
                listNormalAdapter.notifyDataSetChanged();
            }
        }
    }
});

····

holder.gsyVideoPlayer.setPlayTag(TAG);
holder.gsyVideoPlayer.setPlayPosition(position);

```

S
1.1.1  
shuyu 已提交
79
## 1.1.1
80
* 增加了ListVideoUtil全屏是否显示横屏,全屏是否自动旋转
81
* 增加了ListVideoUtils隐藏状态栏和title的接口
S
shuyu 已提交
82

S
shuyu 已提交
83 84


S
readme  
shuyu 已提交
85
## GSYVideoPlayer 播放器控件,抽象类,继承后可以直接使用,参考 StandardGSYVideoPlayer
S
shuyu 已提交
86 87

## 记得调用销毁
S
shuyu 已提交
88
```
S
shuyu 已提交
89 90 91 92 93 94 95
@Override
 protected void onDestroy() {
     super.onDestroy();
     GSYVideoPlayer.releaseAllVideos();
}
```

S
readme  
shuyu 已提交
96
## StandardGSYVideoPlayer 标准的播放播放器,可参考demo中的playActivity
S
shuyu 已提交
97
```
S
shuyu 已提交
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167

设置播放url,第二个参数表示需要边播边缓存
videoPlayer.setUp(url, true, "");

//增加封面
ImageView imageView = new ImageView(this);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setImageResource(R.mipmap.xxx1);
videoPlayer.setThumbImageView(imageView);

//增加title
videoPlayer.getTitleTextView().setVisibility(View.VISIBLE);
videoPlayer.getTitleTextView().setText("测试视频");

//设置返回键
videoPlayer.getBackButton().setVisibility(View.VISIBLE);

//设置旋转
orientationUtils = new OrientationUtils(this, videoPlayer);

//设置全屏按键功能
videoPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        orientationUtils.resolveByClick();
    }
});

//设置返回按键功能
videoPlayer.getBackButton().setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        onBackPressed();
    }
});

//在列表中使用的接口,详情请看Demo中的ListVideoActivity

/**
 * 利用window层播放全屏效果
 *
 * @param context
 * @param actionBar 是否有actionBar,有的话需要隐藏
 * @param statusBar 是否有状态bar,有的话需要隐藏
 */
public void startWindowFullscreen(final Context context, final boolean actionBar, final boolean statusBar)


/**
 * 退出window层播放全屏效果
 */
public void clearFullscreenLayout()

还有用于onBackPressed()的
/**
  * 退出全屏
  *
  */
public static boolean backFromWindowFull(Context context)

@Override
public void onBackPressed() {
    if (StandardGSYVideoPlayer.backFromWindowFull(this)) {
        return;
    }
    super.onBackPressed();
}
```

## OrientationUtils 重力旋转的工具类
S
shuyu 已提交
168
```
S
shuyu 已提交
169 170 171 172 173
//设置旋转
OrientationUtils orientationUtils = new OrientationUtils(Activity, videoPlayer);
```
## ListVideoUtil 列表模式支持支持滑出屏幕继续播放和全屏的工具类
与上面的StandardGSYVideoPlayer实现列表播放和全屏播放不大一样,ListVideoUtil只有一个StandardGSYVideoPlayer,使用外部container来是先全屏
S
shuyu 已提交
174
列表滑动不会影响到播放,具体可以查看demo里的ListVideoActivity和ListVideo2Activity.
S
shuyu 已提交
175
```
S
shuyu 已提交
176 177 178 179
listVideoUtil = new ListVideoUtil(Activity);
设置需要全屏显示的父类
listVideoUtil.setFullViewContainer(videoFullContainer);
.....
S
shuyu 已提交
180

S
shuyu 已提交
181
//对列表进行处理,传入每个item的位置,封面,TAG(如果有多个不同列表,用不同TAG区分),视频列表item的父容器,播放按键
S
shuyu 已提交
182 183 184 185 186 187 188 189 190 191 192 193
/**
 * 动态添加视频播放
 *
 * @param position  位置
 * @param imgView   封面
 * @param tag       TAG类型
 * @param container player的容器
 * @param playBtn   播放按键
 */
public void addVideoPlayer(final int position, View imgView, String tag,
                               ViewGroup container, View playBtn)

S
shuyu 已提交
194 195 196 197 198 199 200 201 202 203 204
holder.playerBtn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        notifyDataSetChanged();
        //设置播放的位置和TAG
        listVideoUtil.setPlayPositionAndTag(position, TAG);
        final String url = "http://baobab.wdjcdn.com/14564977406580.mp4";
        //开始播放
        listVideoUtil.startPlay(url);
    }
});
S
readme  
shuyu 已提交
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236


/**
 * 是否自动旋转
 *
 * @param autoRotation 是否要支持重力旋转
 */
public void setAutoRotation(boolean autoRotation)


/**
 * 是否全屏就马上横屏
 *
 * @param fullLandFrist 如果是,那么全屏的时候就会切换到横屏
 */
public void setFullLandFrist(boolean fullLandFrist)

/**
 * 是否隐藏statusBar
 *
 * @param hideStatusBar true的话会隐藏statusBar,在退出全屏的时候会回复显示
 */
public void setHideStatusBar(boolean hideStatusBar)

/**
 * 是否隐藏actionBar
 *
 * @param hideActionBar true的话会隐藏actionbar,在退出全屏的会回复时候显示
 */
public void setHideActionBar(boolean hideActionBar)


S
shuyu 已提交
237
```
S
shuyu 已提交
238 239 240 241 242 243
### 混淆
```
-keep class tv.danmaku.ijk.** { *; }
-dontwarn tv.danmaku.ijk.**
```

S
shuyu 已提交
244 245
* <h4>//TODO 优化全屏的动画和全屏的效果</h4>
* <h4>//TODO 优化接入的效果</h4>