Skip to content

Commit

Permalink
增加定时器间隔设置,完善VideoView样式设置
Browse files Browse the repository at this point in the history
  • Loading branch information
jiajunhui committed Jan 20, 2021
1 parent 091a8de commit 7703bf6
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 25 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
dependencies {
//该依赖仅包含MediaPlayer解码
implementation 'com.kk.taurus.playerbase:playerbase:3.4.1'
implementation 'com.kk.taurus.playerbase:playerbase:3.4.2'
}
```
Expand All @@ -46,7 +46,7 @@ dependencies {
//该依赖包含exoplayer解码和MediaPlayer解码
//注意exoplayer的最小支持SDK版本为16
implementation 'cn.jiajunhui:exoplayer:341_2122_017'
implementation 'cn.jiajunhui:exoplayer:342_2123_018'
}
```
Expand All @@ -57,7 +57,7 @@ dependencies {
dependencies {
//该依赖包含ijkplayer解码和MediaPlayer解码
implementation 'cn.jiajunhui:ijkplayer:341_088_012'
implementation 'cn.jiajunhui:ijkplayer:342_088_012'
//ijk官方的解码库依赖,较少格式版本且不支持HTTPS。
implementation 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.8'
# Other ABIs: optional
Expand All @@ -76,10 +76,10 @@ dependencies {
//该依赖包含exoplayer解码和MediaPlayer解码
//注意exoplayer的最小支持SDK版本为16
implementation 'cn.jiajunhui:exoplayer:340_2120_016'
implementation 'cn.jiajunhui:exoplayer:342_2123_018'
//该依赖包含ijkplayer解码和MediaPlayer解码
implementation 'cn.jiajunhui:ijkplayer:340_088_011'
implementation 'cn.jiajunhui:ijkplayer:342_088_012'
//ijk官方的解码库依赖,较少格式版本且不支持HTTPS。
implementation 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.8'
# Other ABIs: optional
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.kk.taurus.avplayer.adapter;

import android.graphics.Rect;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
Expand All @@ -11,12 +11,15 @@

import com.kk.taurus.avplayer.R;
import com.kk.taurus.avplayer.bean.RecyclerBaseVideoBean;
import com.kk.taurus.avplayer.cover.LoadingCover;
import com.kk.taurus.playerbase.entity.DataSource;
import com.kk.taurus.playerbase.render.AspectRatio;
import com.kk.taurus.playerbase.receiver.ReceiverGroup;
import com.kk.taurus.playerbase.widget.BaseVideoView;

import java.util.List;

import static com.kk.taurus.avplayer.play.DataInter.ReceiverKey.KEY_LOADING_COVER;

/**
* @author KaraShokZ (张耀中)
* DESCRIPTION
Expand All @@ -32,6 +35,11 @@ public RecyclerBaseVideoContentAdapter(List<RecyclerBaseVideoBean> dataList) {
this.dataList = dataList;
}

public void onDestroy(){
if(typeLiveVideoBvv!=null)
typeLiveVideoBvv.stopPlayback();
}

@NonNull
@Override
public BaseViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
Expand All @@ -54,9 +62,11 @@ public void onBindViewHolder(@NonNull BaseViewHolder holder, int position) {
if (bean.itemType == 1){
if (typeLiveVideoBvv == null){
typeLiveVideoBvv = holder.getView(R.id.activity_recycler_base_video_type_video_bvv);
typeLiveVideoBvv.setOvalRectShape();
// typeLiveVideoBvv.setRoundRectShape(30);
typeLiveVideoBvv.setAspectRatio(AspectRatio.AspectRatio_MATCH_PARENT);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
typeLiveVideoBvv.setRoundRectShape(30);
ReceiverGroup receiverGroup = new ReceiverGroup();
receiverGroup.addReceiver(KEY_LOADING_COVER, new LoadingCover(typeLiveVideoBvv.getContext()));
typeLiveVideoBvv.setReceiverGroup(receiverGroup);
typeLiveVideoBvv.setDataSource(new DataSource(bean.videoUrl));
typeLiveVideoBvv.start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.kk.taurus.avplayer.R;
import com.kk.taurus.avplayer.view.VisualizerView;
import com.kk.taurus.playerbase.AVPlayer;
import com.kk.taurus.playerbase.config.PlayerConfig;
import com.kk.taurus.playerbase.entity.DataSource;
import com.kk.taurus.playerbase.event.EventKey;
import com.kk.taurus.playerbase.event.OnErrorEventListener;
Expand Down Expand Up @@ -62,6 +63,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {

setVolumeControlStream(AudioManager.STREAM_MUSIC);

PlayerConfig.setTimerCounterInterval(50);

mPlayer = new AVPlayer();
mPlayer.setLooping(mSwitchCompat.isChecked());
mPlayer.setVolume(mVolumeLeft, mVolumeRight);
Expand Down Expand Up @@ -193,6 +196,7 @@ public void volumeReduce(View view){
@Override
protected void onDestroy() {
super.onDestroy();
PlayerConfig.setTimerCounterInterval(1000);
mPlayer.destroy();
releaseVisualizer();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@

public class RecyclerBaseVideoActivity extends AppCompatActivity {

RecyclerBaseVideoContentAdapter mAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recycler_base_video);
RecyclerView contentRv = findViewById(R.id.content_rv);
contentRv.setLayoutManager(new LinearLayoutManager(this));
// contentRv.setLayoutManager(new LinearLayoutManager(this,RecyclerView.HORIZONTAL,false));
contentRv.setAdapter(new RecyclerBaseVideoContentAdapter(RecyclerBaseVideoBean.getItemList()));
contentRv.setAdapter(mAdapter = new RecyclerBaseVideoContentAdapter(RecyclerBaseVideoBean.getItemList()));
}

@Override
protected void onDestroy() {
super.onDestroy();
mAdapter.onDestroy();
}
}
12 changes: 6 additions & 6 deletions app/src/main/res/layout/activity_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@
android:textColor="@color/colorPrimary"/>

<Button
android:id="@+id/tv_recycler"
android:id="@+id/tv_videoView"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:onClick="useBaseVideoViewWithRecycler"
android:onClick="useBaseVideoView"
android:textAllCaps="false"
android:text="BaseVideoView的Recycler使用"
android:text="BaseVideoView的使用"
android:textSize="16sp"
android:textColor="@color/buttonTextColor"/>

<Button
android:id="@+id/tv_videoView"
android:id="@+id/tv_recycler"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:onClick="useBaseVideoView"
android:onClick="useBaseVideoViewWithRecycler"
android:textAllCaps="false"
android:text="BaseVideoView的使用"
android:text="BaseVideoView的Recycler使用"
android:textSize="16sp"
android:textColor="@color/buttonTextColor"/>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dp"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#def453">

<com.kk.taurus.playerbase.widget.BaseVideoView
android:id="@+id/activity_recycler_base_video_type_video_bvv"
android:layout_width="250dp"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ project.ext {
lib = [
//module versions
ijksdkVersion = '0.8.8',
exoplayersdkVersion = '2.12.2',
exoplayersdkVersion = '2.12.3',
appcompatVersion = '1.2.0',

playerbaseIjkVersion = '341_088_012',
playerbaseExoVersion = '341_2122_017',
playerbaseVersion = '3.4.1'
playerbaseIjkVersion = '342_088_012',
playerbaseExoVersion = '342_2123_018',
playerbaseVersion = '3.4.2'
]

}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public AVPlayer(){
public AVPlayer(int decoderPlanId){
handleRecordProxy();
//init timer counter proxy.
mTimerCounterProxy = new TimerCounterProxy(1000);
mTimerCounterProxy = new TimerCounterProxy(PlayerConfig.getTimerCounterInterval());
//init internal player instance.
loadInternalPlayer(decoderPlanId);
}
Expand Down Expand Up @@ -378,6 +378,7 @@ public void onProviderError(int code, Bundle bundle) {

@Override
public void setDataSource(DataSource dataSource) {
mTimerCounterProxy.setCounterInterval(PlayerConfig.getTimerCounterInterval());
this.mDataSource = dataSource;
//when data source update, attach listener.
initListener();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class PlayerConfig {

private static boolean playRecordState = false;

private static int timerCounterInterval = 1000;

static {
mPlans = new SparseArrayCompat<>(2);

Expand Down Expand Up @@ -111,4 +113,13 @@ public static boolean isPlayRecordOpen(){
return playRecordState;
}

public static int getTimerCounterInterval() {
if(timerCounterInterval <= 50)
timerCounterInterval = 50;
return timerCounterInterval;
}

public static void setTimerCounterInterval(int timerCounterInterval) {
PlayerConfig.timerCounterInterval = timerCounterInterval;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public TimerCounterProxy(int counterIntervalMs){
this.counterInterval = counterIntervalMs;
}

public void setCounterInterval(int counterInterval) {
this.counterInterval = counterInterval;
}

public void setUseProxy(boolean useProxy) {
this.useProxy = useProxy;
if(!useProxy){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public void getOutline(final View view, final Outline outline) {
}else{
selfRect = new Rect();
view.getDrawingRect(selfRect);
selfRect = RectUtils.getOvalRect(selfRect);
}
outline.setOval(selfRect);
}
Expand Down

0 comments on commit 7703bf6

Please sign in to comment.