Skip to content

Commit 7703bf6

Browse files
committed
增加定时器间隔设置,完善VideoView样式设置
1 parent 091a8de commit 7703bf6

11 files changed

Lines changed: 63 additions & 25 deletions

File tree

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
dependencies {
3535
3636
//该依赖仅包含MediaPlayer解码
37-
implementation 'com.kk.taurus.playerbase:playerbase:3.4.1'
37+
implementation 'com.kk.taurus.playerbase:playerbase:3.4.2'
3838
3939
}
4040
```
@@ -46,7 +46,7 @@ dependencies {
4646
4747
//该依赖包含exoplayer解码和MediaPlayer解码
4848
//注意exoplayer的最小支持SDK版本为16
49-
implementation 'cn.jiajunhui:exoplayer:341_2122_017'
49+
implementation 'cn.jiajunhui:exoplayer:342_2123_018'
5050
5151
}
5252
```
@@ -57,7 +57,7 @@ dependencies {
5757
dependencies {
5858
5959
//该依赖包含ijkplayer解码和MediaPlayer解码
60-
implementation 'cn.jiajunhui:ijkplayer:341_088_012'
60+
implementation 'cn.jiajunhui:ijkplayer:342_088_012'
6161
//ijk官方的解码库依赖,较少格式版本且不支持HTTPS。
6262
implementation 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.8'
6363
# Other ABIs: optional
@@ -76,10 +76,10 @@ dependencies {
7676
7777
//该依赖包含exoplayer解码和MediaPlayer解码
7878
//注意exoplayer的最小支持SDK版本为16
79-
implementation 'cn.jiajunhui:exoplayer:340_2120_016'
79+
implementation 'cn.jiajunhui:exoplayer:342_2123_018'
8080
8181
//该依赖包含ijkplayer解码和MediaPlayer解码
82-
implementation 'cn.jiajunhui:ijkplayer:340_088_011'
82+
implementation 'cn.jiajunhui:ijkplayer:342_088_012'
8383
//ijk官方的解码库依赖,较少格式版本且不支持HTTPS。
8484
implementation 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.8'
8585
# Other ABIs: optional

app/src/main/java/com/kk/taurus/avplayer/adapter/RecyclerBaseVideoContentAdapter.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.kk.taurus.avplayer.adapter;
22

3-
import android.graphics.Rect;
3+
import android.os.Build;
44
import android.view.View;
55
import android.view.ViewGroup;
66
import android.widget.TextView;
@@ -11,12 +11,15 @@
1111

1212
import com.kk.taurus.avplayer.R;
1313
import com.kk.taurus.avplayer.bean.RecyclerBaseVideoBean;
14+
import com.kk.taurus.avplayer.cover.LoadingCover;
1415
import com.kk.taurus.playerbase.entity.DataSource;
15-
import com.kk.taurus.playerbase.render.AspectRatio;
16+
import com.kk.taurus.playerbase.receiver.ReceiverGroup;
1617
import com.kk.taurus.playerbase.widget.BaseVideoView;
1718

1819
import java.util.List;
1920

21+
import static com.kk.taurus.avplayer.play.DataInter.ReceiverKey.KEY_LOADING_COVER;
22+
2023
/**
2124
* @author KaraShokZ (张耀中)
2225
* DESCRIPTION
@@ -32,6 +35,11 @@ public RecyclerBaseVideoContentAdapter(List<RecyclerBaseVideoBean> dataList) {
3235
this.dataList = dataList;
3336
}
3437

38+
public void onDestroy(){
39+
if(typeLiveVideoBvv!=null)
40+
typeLiveVideoBvv.stopPlayback();
41+
}
42+
3543
@NonNull
3644
@Override
3745
public BaseViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
@@ -54,9 +62,11 @@ public void onBindViewHolder(@NonNull BaseViewHolder holder, int position) {
5462
if (bean.itemType == 1){
5563
if (typeLiveVideoBvv == null){
5664
typeLiveVideoBvv = holder.getView(R.id.activity_recycler_base_video_type_video_bvv);
57-
typeLiveVideoBvv.setOvalRectShape();
58-
// typeLiveVideoBvv.setRoundRectShape(30);
59-
typeLiveVideoBvv.setAspectRatio(AspectRatio.AspectRatio_MATCH_PARENT);
65+
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
66+
typeLiveVideoBvv.setRoundRectShape(30);
67+
ReceiverGroup receiverGroup = new ReceiverGroup();
68+
receiverGroup.addReceiver(KEY_LOADING_COVER, new LoadingCover(typeLiveVideoBvv.getContext()));
69+
typeLiveVideoBvv.setReceiverGroup(receiverGroup);
6070
typeLiveVideoBvv.setDataSource(new DataSource(bean.videoUrl));
6171
typeLiveVideoBvv.start();
6272
}

app/src/main/java/com/kk/taurus/avplayer/ui/MusicPlayActivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.kk.taurus.avplayer.R;
1919
import com.kk.taurus.avplayer.view.VisualizerView;
2020
import com.kk.taurus.playerbase.AVPlayer;
21+
import com.kk.taurus.playerbase.config.PlayerConfig;
2122
import com.kk.taurus.playerbase.entity.DataSource;
2223
import com.kk.taurus.playerbase.event.EventKey;
2324
import com.kk.taurus.playerbase.event.OnErrorEventListener;
@@ -62,6 +63,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
6263

6364
setVolumeControlStream(AudioManager.STREAM_MUSIC);
6465

66+
PlayerConfig.setTimerCounterInterval(50);
67+
6568
mPlayer = new AVPlayer();
6669
mPlayer.setLooping(mSwitchCompat.isChecked());
6770
mPlayer.setVolume(mVolumeLeft, mVolumeRight);
@@ -193,6 +196,7 @@ public void volumeReduce(View view){
193196
@Override
194197
protected void onDestroy() {
195198
super.onDestroy();
199+
PlayerConfig.setTimerCounterInterval(1000);
196200
mPlayer.destroy();
197201
releaseVisualizer();
198202
}

app/src/main/java/com/kk/taurus/avplayer/ui/RecyclerBaseVideoActivity.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,20 @@
1212

1313
public class RecyclerBaseVideoActivity extends AppCompatActivity {
1414

15+
RecyclerBaseVideoContentAdapter mAdapter;
16+
1517
@Override
1618
protected void onCreate(Bundle savedInstanceState) {
1719
super.onCreate(savedInstanceState);
1820
setContentView(R.layout.activity_recycler_base_video);
1921
RecyclerView contentRv = findViewById(R.id.content_rv);
2022
contentRv.setLayoutManager(new LinearLayoutManager(this));
21-
// contentRv.setLayoutManager(new LinearLayoutManager(this,RecyclerView.HORIZONTAL,false));
22-
contentRv.setAdapter(new RecyclerBaseVideoContentAdapter(RecyclerBaseVideoBean.getItemList()));
23+
contentRv.setAdapter(mAdapter = new RecyclerBaseVideoContentAdapter(RecyclerBaseVideoBean.getItemList()));
24+
}
25+
26+
@Override
27+
protected void onDestroy() {
28+
super.onDestroy();
29+
mAdapter.onDestroy();
2330
}
2431
}

app/src/main/res/layout/activity_home.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,26 @@
3333
android:textColor="@color/colorPrimary"/>
3434

3535
<Button
36-
android:id="@+id/tv_recycler"
36+
android:id="@+id/tv_videoView"
3737
android:layout_width="match_parent"
3838
android:layout_height="50dp"
3939
android:layout_marginTop="10dp"
4040
android:gravity="center"
41-
android:onClick="useBaseVideoViewWithRecycler"
41+
android:onClick="useBaseVideoView"
4242
android:textAllCaps="false"
43-
android:text="BaseVideoView的Recycler使用"
43+
android:text="BaseVideoView的使用"
4444
android:textSize="16sp"
4545
android:textColor="@color/buttonTextColor"/>
4646

4747
<Button
48-
android:id="@+id/tv_videoView"
48+
android:id="@+id/tv_recycler"
4949
android:layout_width="match_parent"
5050
android:layout_height="50dp"
5151
android:layout_marginTop="10dp"
5252
android:gravity="center"
53-
android:onClick="useBaseVideoView"
53+
android:onClick="useBaseVideoViewWithRecycler"
5454
android:textAllCaps="false"
55-
android:text="BaseVideoView的使用"
55+
android:text="BaseVideoView的Recycler使用"
5656
android:textSize="16sp"
5757
android:textColor="@color/buttonTextColor"/>
5858

app/src/main/res/layout/activity_recycler_base_video_type_video.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:layout_width="300dp"
3+
android:layout_width="match_parent"
44
android:layout_height="300dp"
55
android:background="#def453">
66

77
<com.kk.taurus.playerbase.widget.BaseVideoView
88
android:id="@+id/activity_recycler_base_video_type_video_bvv"
9-
android:layout_width="250dp"
9+
android:layout_width="match_parent"
1010
android:layout_height="250dp"
1111
android:layout_marginLeft="20dp"
1212
android:layout_marginRight="20dp"

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ project.ext {
3737
lib = [
3838
//module versions
3939
ijksdkVersion = '0.8.8',
40-
exoplayersdkVersion = '2.12.2',
40+
exoplayersdkVersion = '2.12.3',
4141
appcompatVersion = '1.2.0',
4242

43-
playerbaseIjkVersion = '341_088_012',
44-
playerbaseExoVersion = '341_2122_017',
45-
playerbaseVersion = '3.4.1'
43+
playerbaseIjkVersion = '342_088_012',
44+
playerbaseExoVersion = '342_2123_018',
45+
playerbaseVersion = '3.4.2'
4646
]
4747

4848
}

playerbase/src/main/java/com/kk/taurus/playerbase/AVPlayer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public AVPlayer(){
8181
public AVPlayer(int decoderPlanId){
8282
handleRecordProxy();
8383
//init timer counter proxy.
84-
mTimerCounterProxy = new TimerCounterProxy(1000);
84+
mTimerCounterProxy = new TimerCounterProxy(PlayerConfig.getTimerCounterInterval());
8585
//init internal player instance.
8686
loadInternalPlayer(decoderPlanId);
8787
}
@@ -378,6 +378,7 @@ public void onProviderError(int code, Bundle bundle) {
378378

379379
@Override
380380
public void setDataSource(DataSource dataSource) {
381+
mTimerCounterProxy.setCounterInterval(PlayerConfig.getTimerCounterInterval());
381382
this.mDataSource = dataSource;
382383
//when data source update, attach listener.
383384
initListener();

playerbase/src/main/java/com/kk/taurus/playerbase/config/PlayerConfig.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public class PlayerConfig {
4646

4747
private static boolean playRecordState = false;
4848

49+
private static int timerCounterInterval = 1000;
50+
4951
static {
5052
mPlans = new SparseArrayCompat<>(2);
5153

@@ -111,4 +113,13 @@ public static boolean isPlayRecordOpen(){
111113
return playRecordState;
112114
}
113115

116+
public static int getTimerCounterInterval() {
117+
if(timerCounterInterval <= 50)
118+
timerCounterInterval = 50;
119+
return timerCounterInterval;
120+
}
121+
122+
public static void setTimerCounterInterval(int timerCounterInterval) {
123+
PlayerConfig.timerCounterInterval = timerCounterInterval;
124+
}
114125
}

playerbase/src/main/java/com/kk/taurus/playerbase/player/TimerCounterProxy.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ public TimerCounterProxy(int counterIntervalMs){
5858
this.counterInterval = counterIntervalMs;
5959
}
6060

61+
public void setCounterInterval(int counterInterval) {
62+
this.counterInterval = counterInterval;
63+
}
64+
6165
public void setUseProxy(boolean useProxy) {
6266
this.useProxy = useProxy;
6367
if(!useProxy){

0 commit comments

Comments
 (0)