Skip to content

Commit

Permalink
Merge pull request #1271 from AstaTus/master
Browse files Browse the repository at this point in the history
Release 2.2.3
  • Loading branch information
AstaTus authored Oct 29, 2021
2 parents 35c6804 + 580c5ab commit 0dab68c
Show file tree
Hide file tree
Showing 28 changed files with 214 additions and 48 deletions.
29 changes: 20 additions & 9 deletions NiuDroidPlayer/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
minSdkVersion 14
targetSdkVersion 27
versionCode 4
versionName "2.1.3"
versionName "2.2.3"
buildConfigField "long", "BUILD_TIMESTAMP", System.currentTimeMillis() + "L"
}
buildTypes {
Expand All @@ -22,7 +22,9 @@ android {
sourceSets {
main {
jniLibs.srcDirs = ['../../releases/openssl']
jniLibs.srcDirs += ['../../releases/qplayer']
if (useSo) {
jniLibs.srcDirs += ['../../releases/qplayer']
}
}
}

Expand All @@ -32,13 +34,22 @@ android {
}

dependencies {
implementation files('../../releases/pldroid-player-2.2.2.jar')
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:design:27.0.2'
implementation 'com.android.support:recyclerview-v7:27.0.2'

if (!useSo) {
implementation project(path: ':mediaEngine')
}

if (!useJar) {
implementation project(path: ':PLDroidPlayer')
} else {
implementation files('../../releases/pldroid-player-2.2.3.jar')
}

implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.journeyapps:zxing-android-embedded:3.0.2@aar'
implementation 'com.google.zxing:core:3.2.0'
implementation 'com.google.zxing:core:3.2.1'
implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
implementation 'com.squareup.okhttp3:okhttp:3.9.1'
implementation 'com.bugsnag:bugsnag-android-ndk:1.+'
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
}
1 change: 1 addition & 0 deletions NiuDroidPlayer/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
android:allowBackup="true"
android:icon="@mipmap/player_icon"
android:label="@string/app_name"
android:testOnly="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import android.view.WindowManager;
import android.widget.Toast;

import com.bugsnag.android.Bugsnag;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
Expand Down Expand Up @@ -59,7 +58,6 @@ protected void onCreate(Bundle savedInstanceState) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
setContentView(com.qiniu.droid.niuplayer.R.layout.activity_main);
Bugsnag.init(this);
isStoragePermissionOK();
initImageLoader();
initView();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void onClickSwitchScreen(View v) {

private PLOnInfoListener mOnInfoListener = new PLOnInfoListener() {
@Override
public void onInfo(int what, int extra) {
public void onInfo(int what, int extra, Object extraData) {
Log.i(TAG, "OnInfo, what = " + what + ", extra = " + extra);
switch (what) {
case PLOnInfoListener.MEDIA_INFO_BUFFERING_START:
Expand Down Expand Up @@ -212,7 +212,7 @@ public void onInfo(int what, int extra) {

private PLOnErrorListener mOnErrorListener = new PLOnErrorListener() {
@Override
public boolean onError(int errorCode) {
public boolean onError(int errorCode, Object extraData) {
Log.e(TAG, "Error happened, errorCode = " + errorCode);
switch (errorCode) {
case PLOnErrorListener.ERROR_CODE_IO_ERROR:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public ViewHolder(View itemView) {
videoView.setLooping(true);
videoView.setOnInfoListener(new PLOnInfoListener() {
@Override
public void onInfo(int i, int i1) {
public void onInfo(int i, int i1, Object extraData) {
if (i == PLOnInfoListener.MEDIA_INFO_VIDEO_RENDERING_START) {
coverImage.setVisibility(View.GONE);
stopPlayImage.setVisibility(View.GONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Choreographer;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -15,8 +16,11 @@

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.pili.pldroid.player.AVOptions;
import com.pili.pldroid.player.PLOnErrorListener;
import com.pili.pldroid.player.PLOnInfoListener;
import com.pili.pldroid.player.PLOnVideoFrameListener;
import com.pili.pldroid.player.widget.PLShortVideoTextureView;
import com.pili.pldroid.player.widget.PLVideoTextureView;
import com.qiniu.droid.niuplayer.R;
import com.qiniu.droid.niuplayer.model.VideoItem;
Expand All @@ -32,19 +36,19 @@ public class ShortVideoListAdapter extends RecyclerView.Adapter<ShortVideoListAd
private ViewHolder mCurViewHolder;
private DisplayImageOptions mDisplayImageOptions;
private long startsystemtime;
private PLVideoTextureView mVideoView;
private PLShortVideoTextureView mVideoView;
private int mCacheStartIndex = -1;
private int mCacheEndIndex = -1;
private final static int CACHE_RANGE = 5;
private HashSet<Integer> mCacheIndexes = new HashSet<Integer>();
private AVOptions mAvOption;



public ShortVideoListAdapter(ArrayList<VideoItem> arrayList, PLVideoTextureView videoView) {
public ShortVideoListAdapter(ArrayList<VideoItem> arrayList, PLShortVideoTextureView videoView) {
mItemList = arrayList;
mVideoView = videoView;
mVideoView.setAVOptions(createAVOptions());

mAvOption = createAVOptions();
mVideoView.setAVOptions(mAvOption);

mDisplayImageOptions = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.defualt_bg) //加载图片时的图片
Expand All @@ -58,7 +62,7 @@ public ShortVideoListAdapter(ArrayList<VideoItem> arrayList, PLVideoTextureView

class ViewHolder extends RecyclerView.ViewHolder {
FrameLayout videoViewFrameLayout;
PLVideoTextureView videoView;
PLShortVideoTextureView videoView;
ImageView coverImage;
TextView nameText;
TextView detailText;
Expand All @@ -70,22 +74,30 @@ class ViewHolder extends RecyclerView.ViewHolder {
View holderRootView;
PLOnErrorListener mPLOnErrorListener = new PLOnErrorListener() {
@Override
public boolean onError(int i) {
public boolean onError(int i, Object extraData) {
Log.d("aa", String.valueOf(i));
return false;
}
};
PLOnInfoListener mPLOnInfoListener = new PLOnInfoListener() {
@Override
public void onInfo(int i, int i1) {
public void onInfo(int i, int i1, Object extraData) {
if (i == PLOnInfoListener.MEDIA_INFO_VIDEO_RENDERING_START) {
coverImage.setVisibility(View.GONE);
mVideoView.getTextureView().setAlpha(1.0f);
Log.d("ShortVideoListAdapter", "first frame time:" + (System.currentTimeMillis() - startsystemtime) + "ms i1=" + i1 + "ms");
changeCache();
}
}
};

PLOnVideoFrameListener mPLOnVideoFrameListener = new PLOnVideoFrameListener() {
@Override
public void onVideoFrameAvailable(byte[] data, int size, int width, int height, int format, long ts) {
Log.d("ShortVideo", "video data ts=" + ts);
}
};



public ViewHolder(View itemView) {
Expand Down Expand Up @@ -117,7 +129,7 @@ public void onStop() {
videoViewFrameLayout.removeView(this.videoView);
}

public void onStart(PLVideoTextureView videoView) {
public void onStart(PLShortVideoTextureView videoView) {
this.videoView = videoView;
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
lp.gravity = Gravity.CENTER;
Expand All @@ -128,6 +140,7 @@ public void onStart(PLVideoTextureView videoView) {

this.videoView.setLooping(true);
this.videoView.setOnInfoListener(mPLOnInfoListener);
// this.videoView.setOnVideoFrameListener(mPLOnVideoFrameListener);
this.videoView.setOnErrorListener(mPLOnErrorListener);
View loadingView = itemView.findViewById(R.id.loading_view);
this.videoView.setBufferingIndicator(loadingView);
Expand Down Expand Up @@ -179,9 +192,13 @@ public void setCurViewHolder(ViewHolder viewHolder) {
public void startCurVideoView() {
if (mCurViewHolder != null) {
mCurViewHolder.onStart(mVideoView);
mVideoView.stop();
mVideoView.setAVOptions(mAvOption);
mVideoView.setVideoPath(mCurViewHolder.videoPath);
startsystemtime = System.currentTimeMillis();
mVideoView.start();
mVideoView.getTextureView().setAlpha(0.0f);

// mVideoView.start();
mCurViewHolder.pausePlayImage.setVisibility(View.GONE);
}
}
Expand Down Expand Up @@ -228,7 +245,7 @@ public void pauseCurVideoView() {

public void stopCurVideoView() {
if (mCurViewHolder != null) {
mVideoView.pause();
mVideoView.stop();
mCurViewHolder.coverImage.setVisibility(View.VISIBLE);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.qiniu.droid.niuplayer.fragment;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
Expand All @@ -10,6 +11,10 @@
import android.view.ViewGroup;
import android.widget.Toast;

import com.pili.pldroid.player.PLMediaPlayer;
import com.pili.pldroid.player.PLOnPreparedListener;
import com.pili.pldroid.player.PLOnSeekCompleteListener;
import com.pili.pldroid.player.widget.PLShortVideoTextureView;
import com.pili.pldroid.player.widget.PLVideoTextureView;
import com.qiniu.droid.niuplayer.R;
import com.qiniu.droid.niuplayer.model.VideoItem;
Expand All @@ -24,7 +29,7 @@ public class ShortVideoListFragment extends Fragment implements FragmentLifecycl
private RecyclerView mVideoList;
private ArrayList<VideoItem> mItemList;
private ShortVideoListAdapter mShortVideoListAdapter;
private PLVideoTextureView mVideoView;
private PLShortVideoTextureView mVideoView;
private volatile boolean mShouldPlay;
private int mCurrentPosition = -1;

Expand All @@ -41,6 +46,11 @@ private void initShortVideoData(final View rootView) {
@Override
public void onSuccess(int statusCode, Object data) {
mItemList = (ArrayList<VideoItem>) data;
// mItemList = new ArrayList<VideoItem>();
// VideoItem item = ((ArrayList<VideoItem>) data).get(0);
// item.setVideoPath("http://pili-live-hdl.artlive.artron.net/artepresscs/artstream74167.flv");
// mItemList.add(item);
// mItemList.add(((ArrayList<VideoItem>) data).get(1));
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -70,7 +80,15 @@ private void initView(View root) {
PagerSnapHelper snapHelper = new PagerSnapHelper();
snapHelper.attachToRecyclerView(mVideoList);

mVideoView = new PLVideoTextureView(getContext());
mVideoView = new PLShortVideoTextureView(getContext());

mVideoView.setOnPreparedListener(new PLOnPreparedListener() {

@Override
public void onPrepared(int preparedTime) {
mVideoView.start();
}
});

mShortVideoListAdapter = new ShortVideoListAdapter(mItemList, mVideoView);
mVideoList.setAdapter(mShortVideoListAdapter);
Expand Down Expand Up @@ -103,6 +121,8 @@ public void onStop() {
}
}



@Override
public void onFragmentPause() {
if (mShortVideoListAdapter != null) {
Expand Down Expand Up @@ -137,6 +157,7 @@ public void onActivityResume() {
public void onActivityDestroy() {
if (mShortVideoListAdapter != null) {
mShortVideoListAdapter.stopCurVideoView();
mVideoView.stopPlayback();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public void setTime(String time) {
mTime = stampToDate(time);
}

public void setVideoPath(String name) {
this.mVideoPath = VIDEO_PATH_PREFIX + name;
this.mName = getVideoName(name);
}

public String getName() {
return mName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public class Config {
public static final String LIVE_TEST_URL = "rtmp://live.hkstv.hk.lxdns.com/live/hks";
public static final String UPGRADE_URL_PREFIX = "https://api-demo.qnsdk.com/v1/upgrade/app?appId=";

public static final String DEFAULT_CACHE_DIR = SDCARD_DIR + "/NiuDroidPlayer";

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Environment;
import android.support.design.widget.TabLayout;
import android.util.Log;
import android.view.View;
Expand All @@ -19,8 +20,10 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;


public class Utils {
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Expand Down Expand Up @@ -130,11 +133,23 @@ public static AVOptions createAVOptions() {
AVOptions options = new AVOptions();
// the unit of timeout is ms
options.setInteger(AVOptions.KEY_PREPARE_TIMEOUT, 10 * 1000);
options.setInteger(AVOptions.KEY_CACHE_BUFFER_DURATION, 200);
options.setInteger(AVOptions.KEY_CACHE_BUFFER_DURATION_SPEED_ADJUST, 0);
HashMap headers = new HashMap<String,String>();
headers.put("Referer","http://video.eebbk.net");
options.setHashMap(AVOptions.KEY_HTTP_HEAD_REFER, headers);
options.setInteger(AVOptions.KEY_LIVE_STREAMING, 0);
// options.setString(AVOptions.KEY_COMP_DRM_KEY, "test123");
// 1 -> hw codec enable, 0 -> disable [recommended]
options.setInteger(AVOptions.KEY_MEDIACODEC, AVOptions.MEDIA_CODEC_SW_DECODE);
options.setInteger(AVOptions.KEY_MEDIACODEC, AVOptions.MEDIA_CODEC_HW_DECODE);
// options.setInteger(AVOptions.KEY_VIDEO_RENDER_EXTERNAL_THREAD, 1);
options.setInteger(AVOptions.KEY_PREFER_FORMAT, AVOptions.PREFER_FORMAT_MP4);
// options.setInteger(AVOptions.KEY_VIDEO_DATA_CALLBACK, 1);
// options.setInteger(AVOptions.KEY_VIDEO_RENDER_EXTERNAL, 1);
// options.setInteger(AVOptions.KEY_START_POSITION, 10 * 1000);
// options.setString(AVOptions.KEY_CACHE_DIR, Config.DEFAULT_CACHE_DIR);


boolean disableLog = false;
options.setInteger(AVOptions.KEY_LOG_LEVEL, disableLog ? 5 : 0);
return options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ public void onProgressChanged(SeekBar bar, int progress, boolean fromuser) {
mLastSeekBarRunnable = new Runnable() {
@Override
public void run() {
Log.i(TAG, "start seek: current time=" + mPlayer.getCurrentPosition());
mPlayer.seekTo(newposition);
}
};
Expand All @@ -434,8 +435,11 @@ public void run() {
}

public void onStopTrackingTouch(SeekBar bar) {
if (!mInstantSeeking)
if (!mInstantSeeking) {
Log.i(TAG, "start seek: current time=" + mPlayer.getCurrentPosition());
mPlayer.seekTo(mDuration * bar.getProgress() / 1000);
}


show(sDefaultTimeout);
mHandler.removeMessages(SHOW_PROGRESS);
Expand Down
7 changes: 7 additions & 0 deletions NiuDroidPlayer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ allprojects {
task clean(type: Delete) {
delete rootProject.buildDir
}



ext {
useJar = true
useSo = true
}
Loading

0 comments on commit 0dab68c

Please sign in to comment.