Skip to content

Commit

Permalink
fix bugs,improve some.
Browse files Browse the repository at this point in the history
  • Loading branch information
jiajunhui committed Mar 22, 2019
1 parent 9da38f3 commit 7729853
Show file tree
Hide file tree
Showing 18 changed files with 141 additions and 31 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ demo示例集成了播放控制组件**ControllerCover**、加载中组件**Load
dependencies {
//---------如果仅使用MediaPlayer解码,使用以下依赖。----------
//该依赖仅包含MediaPlayer解码
implementation 'com.kk.taurus.playerbase:playerbase:3.3.4.4'
implementation 'com.kk.taurus.playerbase:playerbase:3.3.5'
//---------如果使用ExoPlayer解码,使用以下依赖。---------
//该依赖包含exoplayer解码和MediaPlayer解码
//注意exoplayer的最小支持SDK版本为16
implementation 'cn.jiajunhui:exoplayer:3344_291_008'
implementation 'cn.jiajunhui:exoplayer:335_291_008'
//---------如果使用ijkPlayer解码,使用以下依赖。---------
//该依赖包含ijkplayer解码和MediaPlayer解码
implementation 'cn.jiajunhui:ijkplayer:3344_088_007'
implementation 'cn.jiajunhui:ijkplayer:335_088_007'
//ijk官方的解码库依赖,较少格式版本且不支持HTTPS。
implementation 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.8'
# Other ABIs: optional
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"/>

<activity android:name=".HomeActivity" />
<activity
android:name=".HomeActivity"
android:screenOrientation="portrait"/>

<activity
android:name=".ui.BaseVideoViewActivity"
Expand All @@ -56,6 +58,7 @@
android:screenOrientation="portrait"/>
<activity
android:name=".ui.window.FloatWindowActivity"
android:launchMode="singleTask"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"/>
<activity
Expand Down
16 changes: 12 additions & 4 deletions app/src/main/java/com/kk/taurus/avplayer/cover/GestureCover.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,17 @@ public void run() {
@Override
public String[] filterKeys() {
return new String[]{
DataInter.Key.KEY_COMPLETE_SHOW};
DataInter.Key.KEY_COMPLETE_SHOW,
DataInter.Key.KEY_IS_LANDSCAPE
};
}

@Override
public void onValueUpdate(String key, Object value) {
if(key.equals(DataInter.Key.KEY_COMPLETE_SHOW)){
if(DataInter.Key.KEY_COMPLETE_SHOW.equals(key)){
setGestureEnable(!(boolean) value);
}else if(DataInter.Key.KEY_IS_LANDSCAPE.equals(key)){
notifyWH();
}
}
};
Expand All @@ -144,13 +148,17 @@ protected void onCoverAttachedToWindow() {
getView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
mWidth = getView().getWidth();
mHeight = getView().getHeight();
notifyWH();
getView().getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}

private void notifyWH() {
mWidth = getView().getWidth();
mHeight = getView().getHeight();
}

@Override
protected void onCoverDetachedToWindow() {
super.onCoverDetachedToWindow();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.kk.taurus.avplayer.play;

import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;

import com.kk.taurus.avplayer.utils.DataUtils;
import com.kk.taurus.playerbase.entity.DataSource;
import com.kk.taurus.playerbase.provider.BaseDataProvider;

public class DemoDataProvider extends BaseDataProvider {

private Handler mHandler = new Handler(Looper.getMainLooper());
private Runnable mDelayRunnable;

@Override
public void handleSourceData(final DataSource sourceData) {
if(TextUtils.isEmpty(sourceData.getData())){
cancel();
//模拟请求数据的过程
mHandler.postDelayed(mDelayRunnable = new Runnable() {
@Override
public void run() {
DataSource data = new DataSource(DataUtils.VIDEO_URL_08);
data.setTitle("音乐和艺术如何改变世界");
//success result data
onProviderMediaDataSuccess(data);
//if occur error, you can call this method
//onProviderMediaDataError(bundle);
}
}, 1000);
}else{
onProviderMediaDataSuccess(sourceData);
}
}

@Override
public void cancel() {
if(mDelayRunnable!=null)
mHandler.removeCallbacks(mDelayRunnable);
}

@Override
public void destroy() {
cancel();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class BaseVideoViewActivity extends AppCompatActivity implements

private boolean hasStart;
private RecyclerView mRecycler;
private SettingAdapter mAdapter;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
Expand Down Expand Up @@ -77,7 +78,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {

private void initPlay(){
if(!hasStart){
DataSource dataSource = new DataSource(DataUtils.VIDEO_URL_08);
DataSource dataSource = new DataSource(DataUtils.VIDEO_URL_09);
dataSource.setTitle("音乐和艺术如何改变世界");
mVideoView.setDataSource(dataSource);
mVideoView.start();
Expand All @@ -89,10 +90,12 @@ private void initPlay(){
public void onPlayerEvent(int eventCode, Bundle bundle) {
switch (eventCode){
case OnPlayerEventListener.PLAYER_EVENT_ON_VIDEO_RENDER_START:
mRecycler.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
SettingAdapter mAdapter = new SettingAdapter(this, SettingItem.initSettingList());
mAdapter.setOnItemClickListener(this);
mRecycler.setAdapter(mAdapter);
if(mAdapter==null){
mRecycler.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
mAdapter = new SettingAdapter(this, SettingItem.initSettingList());
mAdapter.setOnItemClickListener(this);
mRecycler.setAdapter(mAdapter);
}
break;
}
}
Expand Down Expand Up @@ -132,7 +135,7 @@ public void requestRetry(BaseVideoView videoView, Bundle bundle) {
};

private void replay(){
mVideoView.setDataSource(new DataSource(DataUtils.VIDEO_URL_01));
mVideoView.setDataSource(new DataSource(DataUtils.VIDEO_URL_09));
mVideoView.start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,21 @@ public void onConfigurationChanged(Configuration newConfig) {
mReceiverGroup.getGroupValue().putBoolean(DataInter.Key.KEY_IS_LANDSCAPE, isLandScape);
}

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
enterFullScreen();
}

private void enterFullScreen(){
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
if(mWhoIntentFullScreen==WINDOW_INTENT_FULL_SCREEN){
normalPlay();
if(PUtil.isTopActivity(this)){
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
if(mWhoIntentFullScreen==WINDOW_INTENT_FULL_SCREEN){
normalPlay();
}
}else{
startActivity(new Intent(getApplicationContext(), FloatWindowActivity.class));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
import com.kk.taurus.avplayer.R;
import com.kk.taurus.avplayer.cover.CloseCover;
import com.kk.taurus.avplayer.play.DataInter;
import com.kk.taurus.avplayer.play.DemoDataProvider;
import com.kk.taurus.avplayer.play.ReceiverGroupManager;
import com.kk.taurus.avplayer.utils.PUtil;
import com.kk.taurus.avplayer.utils.WindowPermissionCheck;
import com.kk.taurus.playerbase.assist.OnVideoViewEventHandler;
import com.kk.taurus.playerbase.entity.DataSource;
import com.kk.taurus.playerbase.player.IPlayer;
import com.kk.taurus.playerbase.provider.IDataProvider;
import com.kk.taurus.playerbase.receiver.ReceiverGroup;
import com.kk.taurus.playerbase.widget.BaseVideoView;
import com.kk.taurus.playerbase.window.FloatWindowParams;
Expand All @@ -32,6 +34,8 @@ public class WindowVideoViewActivity extends AppCompatActivity {

DataSource mDataSource;

IDataProvider mDataProvider;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -72,8 +76,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
mWindowVideoView.setReceiverGroup(receiverGroup);

mDataSource = new DataSource();
mDataSource.setData("https://mov.bn.netease.com/open-movie/nos/mp4/2018/01/12/SD70VQJ74_sd.mp4");
mDataSource.setTitle("不想从被子里出来");
mDataSource.setId(1234567);
mWindowVideoView.setDataProvider(mDataProvider = new DemoDataProvider());
mWindowVideoView.setDataSource(mDataSource);

}

Expand Down Expand Up @@ -137,15 +142,14 @@ protected void onResume() {
return;
if(mWindowVideoView.isInPlaybackState())
mWindowVideoView.resume();
else
mWindowVideoView.rePlay(0);
}

@Override
protected void onDestroy() {
super.onDestroy();
mWindowVideoView.close();
mWindowVideoView.stopPlayback();
mDataProvider.destroy();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class DataUtils {
public static final String VIDEO_URL_06 = "http://jiajunhui.cn/video/big_buck_bunny.mp4";
public static final String VIDEO_URL_07 = "http://jiajunhui.cn/video/trailer.mp4";
public static final String VIDEO_URL_08 = "https://mov.bn.netease.com/open-movie/nos/mp4/2017/12/04/SD3SUEFFQ_hd.mp4";
public static final String VIDEO_URL_09 = "https://mov.bn.netease.com/open-movie/nos/mp4/2017/05/31/SCKR8V6E9_hd.mp4";

public static String[] urls = new String[]{
VIDEO_URL_01,
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0'

Expand Down
2 changes: 1 addition & 1 deletion exoplayer/bintray.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

// 这个version是区分library版本的,因此当我们需要更新library时记得修改这个version
version = "3344_291_008"
version = "335_291_008"

def siteUrl = 'https://github.com/jiajunhui/PlayerBase' // 项目的主页
def gitUrl = 'https://github.com/jiajunhui/PlayerBase.git' // Git仓库的url
Expand Down
2 changes: 1 addition & 1 deletion exoplayer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')

api "com.google.android.exoplayer:exoplayer:2.9.1"
api 'com.kk.taurus.playerbase:playerbase:3.3.4.4'
api 'com.kk.taurus.playerbase:playerbase:3.3.5'
// api project(':playerbase')
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Apr 29 10:03:55 CST 2018
#Tue Mar 19 10:07:48 CST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
2 changes: 1 addition & 1 deletion ijkplayer/bintray.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

// 这个version是区分library版本的,因此当我们需要更新library时记得修改这个version
version = "3344_088_007"
version = "335_088_007"

def siteUrl = 'https://github.com/jiajunhui/PlayerBase' // 项目的主页
def gitUrl = 'https://github.com/jiajunhui/PlayerBase.git' // Git仓库的url
Expand Down
2 changes: 1 addition & 1 deletion ijkplayer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')

api 'tv.danmaku.ijk.media:ijkplayer-java:0.8.8'
api 'com.kk.taurus.playerbase:playerbase:3.3.4.4'
api 'com.kk.taurus.playerbase:playerbase:3.3.5'
// api project(':playerbase')
}
2 changes: 1 addition & 1 deletion playerbase/bintray.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

// 这个version是区分library版本的,因此当我们需要更新library时记得修改这个version
version = "3.3.4.4"
version = "3.3.5"

def siteUrl = 'https://github.com/jiajunhui/PlayerBase' // 项目的主页
def gitUrl = 'https://github.com/jiajunhui/PlayerBase.git' // Git仓库的url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,21 @@ public static AssetFileDescriptor getAssetsFileDescriptor(Context context, Strin
return null;
}

@Override
public String toString() {
return "DataSource{" +
"tag='" + tag + '\'' +
", sid='" + sid + '\'' +
", data='" + data + '\'' +
", title='" + title + '\'' +
", id=" + id +
", uri=" + uri +
", extra=" + extra +
", timedTextSource=" + timedTextSource +
", assetsPath='" + assetsPath + '\'' +
", rawId=" + rawId +
", startPos=" + startPos +
", isLive=" + isLive +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import android.os.Bundle;
import android.support.annotation.NonNull;

import com.kk.taurus.playerbase.entity.DataSource;
import com.kk.taurus.playerbase.event.BundlePool;
import com.kk.taurus.playerbase.event.EventKey;

/**
* Created by Taurus on 2018/4/15.
*/
Expand All @@ -44,11 +48,23 @@ protected final void onProviderDataStart(){
* send media data for player. must invocation.
* @param bundle
*/
@Deprecated
protected final void onProviderMediaDataSuccess(@NonNull Bundle bundle){
if(mOnProviderListener!=null)
mOnProviderListener.onProviderDataSuccess(PROVIDER_CODE_SUCCESS_MEDIA_DATA, bundle);
}

/**
* send media data for player. must invocation.
* @param dataSource
*/
protected final void onProviderMediaDataSuccess(@NonNull DataSource dataSource){
Bundle bundle = BundlePool.obtain();
bundle.putSerializable(EventKey.SERIALIZABLE_DATA, dataSource);
if(mOnProviderListener!=null)
mOnProviderListener.onProviderDataSuccess(PROVIDER_CODE_SUCCESS_MEDIA_DATA, bundle);
}

/**
* send extra data, usually custom by yourself according to your need.
* @param code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public String generatorKey(DataSource dataSource) {
}else if(rawId > 0){
return String.valueOf(rawId);
}
return null;
return dataSource.toString();
}

}

0 comments on commit 7729853

Please sign in to comment.