diff --git a/README.md b/README.md index 1ecb6816..e889ce34 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,14 @@ -

JiaoZiVideoPlayer

--- -

- - - - -

- 高度自定义的安卓视频框架 -## 置顶消息: - -群主微信进饺子粉丝群,沟通重心从Q群转移到微信群。微信:lipangit备注JZVD,Q群:490442439, 2群:761899104, 验证信息:jzvd, 微信公众号:jzvdjzt,QQ:1066666651,[Telegram](https://t.me/jiaozitoken),[Weibo](http://weibo.com/2342820395/profile?topnav=1&wvr=6&is_all=1),[公众号文章](https://github.com/Jzvd/JiaoZiVideoPlayer/wiki/%E5%85%AC%E4%BC%97%E5%8F%B7%E6%96%87%E7%AB%A0) - - +[中文文档](http://jzvd.org) -为了增加项目质量,促进项目进度,调用社群力量,方便社群管理,推出基于以太坊ERC-20的数字通证[JiaoZiToken(JZT)(饺子Token)](https://github.com/JZVD/JZT),必定大有可为。 - -#### [找点事做挣饺子币](https://github.com/Jzvd/JiaoZiVideoPlayer/wiki/%E6%89%BE%E7%82%B9%E4%BA%8B%E5%81%9A%EF%BC%8C%E6%8C%A3%E7%82%B9%E9%A5%BA%E5%AD%90%E5%B8%81) - -#### [购买咨询服务送饺子币](https://github.com/Jzvd/JiaoZiVideoPlayer/wiki/%E8%B4%AD%E4%B9%B0%E5%92%A8%E8%AF%A2%E6%9C%8D%E5%8A%A1%E9%80%81%E9%A5%BA%E5%AD%90%E5%B8%81) - -## 文档 - -- [文档 - API](https://github.com/Jzvd/JiaoZiVideoPlayer/wiki/%E6%96%87%E6%A1%A3-%E2%80%94-API),下载安装[Demo jiaozivideoplayer-7.5.0.apk](https://github.com/Jzvd/JiaoZiVideoPlayer/releases/download/v7.5.0/jiaozivideoplayer-7.5.0.apk),仔细过一遍Demo -- [文档 - 自定义Jzvd](https://github.com/Jzvd/JiaoZiVideoPlayer/wiki/%E6%96%87%E6%A1%A3-%E2%80%94-%E8%87%AA%E5%AE%9A%E4%B9%89Jzvd),继承JzvdStd实现自己的播放器 -- [文档 - 自定义播放内核](https://github.com/Jzvd/JiaoZiVideoPlayer/wiki/%E6%96%87%E6%A1%A3-%E2%80%94-%E8%87%AA%E5%AE%9A%E4%B9%89%E6%92%AD%E6%94%BE%E5%86%85%E6%A0%B8),测试哪个播放内核适合自己的项目 - -## 效果 - - - - +[下载Demo](https://github.com/Jzvd/JZVideo/releases/download/v7.6.0/jiaozivideoplayer-7.6.0.apk) ## QuickStart 1.添加类库 ```gradle -implementation 'cn.jzvd:jiaozivideoplayer:7.5.0' +implementation 'cn.jzvd:jiaozivideoplayer:7.6.0' ``` 2.添加布局 @@ -92,18 +63,17 @@ protected void onPause() { -keep interface tv.danmaku.ijk.media.player.** { *; } ``` -即便是自定义UI,或者对Library有过修改,依然要通过上述步骤使用播放器。 - -## 注意: -1. 7.0版本之后要在JzvdStd外面包一层Layout -2. 如果引入配置失败,根据失败的log检查是否添加了Java8的配置,或者升级环境到最新的稳定版 - -## JZVD DEMO说明 -

JiaoZiVideoPlayer

+## 效果 +

+ +

+

+ +

## License MIT -Copyright (c) 2015-2020 李盼 +Copyright (c) 2015-2020 jzvd.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/build.gradle b/build.gradle index 353dce49..c991cbcc 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,14 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.72' + ext.kotlin_version = '1.4.21' repositories { jcenter() google() - maven { url 'https://maven.aliyun.com/repository/releases' } } dependencies { - classpath 'com.android.tools.build:gradle:4.0.1' + classpath 'com.android.tools.build:gradle:4.1.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files } } @@ -21,8 +17,8 @@ allprojects { jcenter() google() maven { url "https://jitpack.io" } - maven { url "https://maven.google.com" } - maven { url 'https://maven.aliyun.com/repository/releases' } + maven { url "https://maven.aliyun.com/repository/public" } //jcenter & central + maven { url "https://maven.aliyun.com/repository/google" } } } diff --git a/demo/build.gradle b/demo/build.gradle index 240a542d..3694f612 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -1,15 +1,17 @@ apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' android { compileSdkVersion 30 - buildToolsVersion "30.0.2" + buildToolsVersion "30.0.3" defaultConfig { applicationId "cn.jzvd.demo" minSdkVersion 16 targetSdkVersion 30 - versionCode 105 - versionName "7.5.0" + versionCode 106 + versionName "7.6.0" + multiDexEnabled true ndk { // add support lib abiFilters 'armeabi-v7a' //, 'arm64-v8a'//, "mips" //,'armeabi''x86',, 'x86_64', @@ -47,21 +49,26 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - testImplementation 'junit:junit:4.12' - implementation 'androidx.appcompat:appcompat:1.2.0' - implementation 'com.google.android.material:material:1.2.0' implementation project(':library') - implementation 'tv.danmaku.ijk.media:ijkplayer-java:0.8.8' - implementation 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.4' + implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.recyclerview:recyclerview:1.1.0' - implementation 'com.danikula:videocache:2.7.0' + implementation 'com.android.support.constraint:constraint-layout:2.0.4' + implementation 'com.google.android.material:material:1.2.1' + implementation 'com.google.android.exoplayer:exoplayer:2.12.1' implementation 'com.github.bumptech.glide:glide:4.11.0' - implementation 'com.google.android.exoplayer:exoplayer:2.11.3' - debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.3' - implementation 'com.android.support.constraint:constraint-layout:2.0.1' implementation 'com.github.wseemann:FFmpegMediaMetadataRetriever-core:1.0.15' implementation 'com.github.wseemann:FFmpegMediaMetadataRetriever-native:1.0.15' implementation 'com.github.ittianyu:BottomNavigationViewEx:2.0.4' + implementation 'com.github.ctiao:DanmakuFlameMaster:0.9.25' + implementation 'com.github.ctiao:ndkbitmap-armv7a:0.9.21' + implementation 'com.danikula:videocache:2.7.0' implementation 'com.aliyun.sdk.android:AliyunPlayer:4.5.0-full' implementation 'com.alivc.conan:AlivcConan:0.9.5' + implementation 'com.scwang.smart:refresh-layout-kernel:2.0.1' + implementation 'com.scwang.smart:refresh-header-material:2.0.1' + implementation 'com.scwang.smart:refresh-footer-classics:2.0.1' + implementation 'tv.danmaku.ijk.media:ijkplayer-java:0.8.8' + implementation 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.4' + debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.3' + } diff --git a/demo/src/main/AndroidManifest.xml b/demo/src/main/AndroidManifest.xml index d5804e44..9b545629 100644 --- a/demo/src/main/AndroidManifest.xml +++ b/demo/src/main/AndroidManifest.xml @@ -72,10 +72,6 @@ android:name=".Tab_1_Basic.OrientationActivity" android:configChanges="orientation|screenSize|keyboardHidden" android:screenOrientation="portrait" /> - + \ No newline at end of file diff --git a/demo/src/main/java/cn/jzvd/demo/CustomJzvd/JzvdDanmu.java b/demo/src/main/java/cn/jzvd/demo/CustomJzvd/JzvdDanmu.java new file mode 100644 index 00000000..27aee22b --- /dev/null +++ b/demo/src/main/java/cn/jzvd/demo/CustomJzvd/JzvdDanmu.java @@ -0,0 +1,244 @@ +package cn.jzvd.demo.CustomJzvd; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.RectF; +import android.graphics.drawable.Drawable; +import android.text.Spannable; +import android.text.SpannableStringBuilder; +import android.text.TextPaint; +import android.util.AttributeSet; +import android.util.Log; + +import androidx.core.content.ContextCompat; + +import cn.jzvd.JzvdStd; +import cn.jzvd.demo.BuildConfig; +import cn.jzvd.demo.R; +import cn.jzvd.demo.utils.DipAndPx; +import master.flame.danmaku.controller.DrawHandler; +import master.flame.danmaku.danmaku.model.BaseDanmaku; +import master.flame.danmaku.danmaku.model.DanmakuTimer; +import master.flame.danmaku.danmaku.model.IDanmakus; +import master.flame.danmaku.danmaku.model.IDisplayer; +import master.flame.danmaku.danmaku.model.android.DanmakuContext; +import master.flame.danmaku.danmaku.model.android.Danmakus; +import master.flame.danmaku.danmaku.model.android.SpannedCacheStuffer; +import master.flame.danmaku.danmaku.parser.BaseDanmakuParser; +import master.flame.danmaku.ui.widget.DanmakuView; +import cn.jzvd.demo.utils.CenteredImageSpan; + +import java.util.HashMap; + +public class JzvdDanmu extends JzvdStd { + public DanmakuView danmakuView; + private DanmakuContext danmakuContext; + private BaseDanmakuParser danmakuParser; + + + public JzvdDanmu(Context context) { + super(context); + } + + public JzvdDanmu(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + public int getLayoutId() { + return R.layout.jz_layout_danmu; + } + + @Override + public void init(Context context) { + super.init(context); + danmakuView = findViewById(R.id.jz_danmu); + HashMap overlappingEnablePair = new HashMap(); + overlappingEnablePair.put(BaseDanmaku.TYPE_SCROLL_RL, true); + overlappingEnablePair.put(BaseDanmaku.TYPE_FIX_TOP, true); + HashMap maxLinesPair = new HashMap(); + maxLinesPair.put(BaseDanmaku.TYPE_SCROLL_RL, 5); // 滚动弹幕最大显示5行,可设置多种类型限制行数 + danmakuContext = DanmakuContext.create(); + danmakuContext.setDanmakuStyle(IDisplayer.DANMAKU_STYLE_STROKEN, 3) + .setDuplicateMergingEnabled(false) + .setScrollSpeedFactor(1.2f) + .setScaleTextSize(1.2f) + .setMaximumLines(maxLinesPair) + .preventOverlapping(overlappingEnablePair).setDanmakuMargin(40); + danmakuParser = new BaseDanmakuParser() { + @Override + protected IDanmakus parse() { + return new Danmakus(); + } + }; + danmakuView.setCallback(new DrawHandler.Callback() { + @Override + public void prepared() { + danmakuView.start(); + } + + @Override + public void updateTimer(DanmakuTimer timer) { + + } + + @Override + public void danmakuShown(BaseDanmaku danmaku) { + + } + + @Override + public void drawingFinished() { + + } + }); + danmakuView.showFPS(BuildConfig.DEBUG); + danmakuView.enableDanmakuDrawingCache(true); + } + + //onState 代表了播放器引擎的回调,播放视频各个过程的状态的回调 + @Override + public void onStateNormal() { + super.onStateNormal(); + } + + @Override + public void onStatePreparing() { + super.onStatePreparing(); + if (danmakuView.isPrepared()) { + danmakuView.restart(); + } + danmakuView.prepare(danmakuParser, danmakuContext); + } + + @Override + public void onStatePlaying() { + super.onStatePlaying(); + if (danmakuView.isPrepared() && danmakuView.isPaused()) { + danmakuView.resume(); + } + + } + + @Override + public void onStatePause() { + super.onStatePause(); + if (danmakuView.isPrepared()) { + danmakuView.pause(); + } + } + + public void releaseDanMu() { + danmakuView.release(); + danmakuView = null; + } + + @Override + public void onStateError() { + super.onStateError(); + danmakuView.release(); + } + + @Override + public void onStateAutoComplete() { + super.onStateAutoComplete(); + danmakuView.stop(); + danmakuView.clear(); + danmakuView.clearDanmakusOnScreen(); + } + + public void showDanmmu() { + danmakuView.show(); + } + + public void hideDanmmu() { + danmakuView.hide(); + } + + /** + * 发送文字弹幕 + * + * @param text 弹幕文字 + * @param isSelf 是不是自己发的 + */ + public void addDanmaku(String text, boolean isSelf) { + danmakuContext.setCacheStuffer(new SpannedCacheStuffer(), null); + BaseDanmaku danmaku = danmakuContext.mDanmakuFactory.createDanmaku(BaseDanmaku.TYPE_SCROLL_RL); + if (danmaku == null) { + return; + } + danmaku.text = text; + danmaku.priority = 3; + danmaku.isLive = false; + danmaku.setTime(danmakuView.getCurrentTime() + 1200); + danmaku.textSize = DipAndPx.dip2px(getContext(), isSelf ? 20 : 12); + danmaku.textColor = isSelf ? Color.BLUE : Color.WHITE; + danmaku.textShadowColor = Color.GRAY; + danmaku.underlineColor = isSelf ? Color.GREEN : Color.TRANSPARENT; + danmaku.borderColor = isSelf ? Color.GREEN : Color.TRANSPARENT; + danmakuView.addDanmaku(danmaku); + } + + /** + * 发送自定义弹幕 + */ + public void addDanmakuWithDrawable() { + danmakuContext.setCacheStuffer(new BackgroundCacheStuffer(), null); + BaseDanmaku danmaku = danmakuContext.mDanmakuFactory.createDanmaku(BaseDanmaku.TYPE_SCROLL_RL); + if (danmaku == null) { + return; + } + Drawable drawable = ContextCompat.getDrawable(getContext(), R.mipmap.ic_launcher); + int size = DipAndPx.dip2px(getContext(), 20); + drawable.setBounds(0, 0, size, size); + danmaku.text = createSpannable(drawable); + danmaku.priority = 4; // 可能会被各种过滤器过滤并隐藏显示 + danmaku.isLive = false; + danmaku.setTime(danmakuView.getCurrentTime() + 1200); + danmaku.textSize = DipAndPx.dip2px(getContext(), 12); + danmaku.textColor = Color.RED; + danmaku.textShadowColor = Color.WHITE; + danmakuView.addDanmaku(danmaku); + + } + + private SpannableStringBuilder createSpannable(Drawable drawable) { + String text = "bitmap"; + SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text); + CenteredImageSpan span = new CenteredImageSpan(drawable);//ImageSpan.ALIGN_BOTTOM); + spannableStringBuilder.setSpan(span, 0, text.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); + spannableStringBuilder.append(" 自定义弹幕起飞~"); + return spannableStringBuilder; + } + + /** + * 绘制背景(自定义弹幕样式) + */ + private class BackgroundCacheStuffer extends SpannedCacheStuffer { + // 通过扩展SimpleTextCacheStuffer或SpannedCacheStuffer个性化你的弹幕样式 + final Paint paint = new Paint(); + + @Override + public void measure(BaseDanmaku danmaku, TextPaint paint, boolean fromWorkerThread) { +// danmaku.padding = 5; // 在背景绘制模式下增加padding + super.measure(danmaku, paint, fromWorkerThread); + } + + @Override + public void drawBackground(BaseDanmaku danmaku, Canvas canvas, float left, float top) { + paint.setAntiAlias(true); + paint.setColor(Color.parseColor("#65777777"));//黑色 普通 + int radius = DipAndPx.dip2px(getContext(), 10); + canvas.drawRoundRect(new RectF(left, top, left + danmaku.paintWidth, top + danmaku.paintHeight), radius, radius, paint); + } + + @Override + public void drawStroke(BaseDanmaku danmaku, String lineText, Canvas canvas, float left, float top, Paint paint) { + // 禁用描边绘制 + } + } + + +} diff --git a/demo/src/main/java/cn/jzvd/demo/CustomJzvd/JzvdStdAutoOrizental.java b/demo/src/main/java/cn/jzvd/demo/CustomJzvd/JzvdStdAutoOrizental.java new file mode 100644 index 00000000..9c194932 --- /dev/null +++ b/demo/src/main/java/cn/jzvd/demo/CustomJzvd/JzvdStdAutoOrizental.java @@ -0,0 +1,47 @@ +package cn.jzvd.demo.CustomJzvd; + +import android.content.Context; +import android.content.pm.ActivityInfo; +import android.util.AttributeSet; +import android.util.Log; +import android.view.View; + +import androidx.annotation.LongDef; + +import cn.jzvd.Jzvd; +import cn.jzvd.JzvdStd; +import cn.jzvd.demo.R; + +/** + * 根据视频宽高自适应全屏方向 + */ +public class JzvdStdAutoOrizental extends JzvdStd { + + public JzvdStdAutoOrizental(Context context) { + super(context); + } + + public JzvdStdAutoOrizental(Context context, AttributeSet attrs) { + super(context, attrs); + } + + + @Override + public void onVideoSizeChanged(int width, int height) { + super.onVideoSizeChanged(width, height); + if (width > 0 && height > 0) { + if (height > width) { + Jzvd.FULLSCREEN_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; + } else { + Jzvd.FULLSCREEN_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; + } + } + } + + @Override + public void reset() { + super.reset(); + Jzvd.FULLSCREEN_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; + Jzvd.NORMAL_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; + } +} diff --git a/demo/src/main/java/cn/jzvd/demo/CustomJzvd/JzvdStdRound.java b/demo/src/main/java/cn/jzvd/demo/CustomJzvd/JzvdStdRound.java new file mode 100644 index 00000000..93e7fc1e --- /dev/null +++ b/demo/src/main/java/cn/jzvd/demo/CustomJzvd/JzvdStdRound.java @@ -0,0 +1,87 @@ +package cn.jzvd.demo.CustomJzvd; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.PaintFlagsDrawFilter; +import android.graphics.Path; +import android.graphics.RectF; +import android.util.AttributeSet; + +import java.util.UUID; + +import cn.jzvd.JzvdStd; +import cn.jzvd.demo.R; + +public class JzvdStdRound extends JzvdStd { + + private int radius; + private int leftTopRadius; + private int rightTopRadius; + private int rightBottomRadius; + private int leftBottomRadius; + public JzvdStdRound(Context context) { + super(context); + } + public JzvdStdRound(Context context, AttributeSet attrs) { + super(context, attrs); + initAttrs(context, attrs); + } + + void initAttrs(Context context, AttributeSet attrs) { + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.JzvdStdRound); + radius = a.getDimensionPixelSize(R.styleable.JzvdStdRound_radius, 0); + leftTopRadius = a.getDimensionPixelSize(R.styleable.JzvdStdRound_left_top_radius, 0); + rightTopRadius = a.getDimensionPixelSize(R.styleable.JzvdStdRound_right_top_radius, 0); + rightBottomRadius = a.getDimensionPixelSize(R.styleable.JzvdStdRound_right_bottom_radius, 0); + leftBottomRadius = a.getDimensionPixelSize(R.styleable.JzvdStdRound_left_bottom_radius, 0); + } + + + public void setRadius(int radius){ + this.radius = radius; + invalidate(); + } + + public void setLeftTopRadius(int leftTopRadius) { + this.leftTopRadius = leftTopRadius; + invalidate(); + } + + + public void setRightTopRadius(int rightTopRadius) { + this.rightTopRadius = rightTopRadius; + invalidate(); + } + + + public void setRightBottomRadius(int rightBottomRadius) { + this.rightBottomRadius = rightBottomRadius; + invalidate(); + } + + public void setLeftBottomRadius(int leftBottomRadius) { + this.leftBottomRadius = leftBottomRadius; + invalidate(); + } + + @Override + protected void dispatchDraw(Canvas canvas) { + Path path = new Path(); + if (radius > 0) { + path.addRoundRect(new RectF(0, 0, getMeasuredWidth(), getMeasuredHeight()), + radius, radius, Path.Direction.CW); + } else { + path.addRoundRect(new RectF(0, 0, getMeasuredWidth(), getMeasuredHeight()), + new float[]{leftTopRadius, leftTopRadius, rightTopRadius, rightTopRadius, + rightBottomRadius, rightBottomRadius, leftBottomRadius, leftBottomRadius}, + Path.Direction.CW); + canvas.setDrawFilter(new PaintFlagsDrawFilter(0, + Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG)); + } + canvas.clipPath(path); + super.dispatchDraw(canvas); + } +} + diff --git a/demo/src/main/java/cn/jzvd/demo/CustomJzvd/MyJzvdStdNoTitleNoClarity.java b/demo/src/main/java/cn/jzvd/demo/CustomJzvd/MyJzvdStdNoTitleNoClarity.java index 563af7b1..18b46db7 100644 --- a/demo/src/main/java/cn/jzvd/demo/CustomJzvd/MyJzvdStdNoTitleNoClarity.java +++ b/demo/src/main/java/cn/jzvd/demo/CustomJzvd/MyJzvdStdNoTitleNoClarity.java @@ -3,9 +3,10 @@ import android.content.Context; import android.util.AttributeSet; +import cn.jzvd.JzvdStd; import cn.jzvd.demo.R; -public class MyJzvdStdNoTitleNoClarity extends MyJzvdStd { +public class MyJzvdStdNoTitleNoClarity extends JzvdStd { public MyJzvdStdNoTitleNoClarity(Context context) { super(context); diff --git a/demo/src/main/java/cn/jzvd/demo/CustomMedia/JZMediaAliyun.java b/demo/src/main/java/cn/jzvd/demo/CustomMedia/JZMediaAliyun.java index ade29941..2b7ccfd6 100644 --- a/demo/src/main/java/cn/jzvd/demo/CustomMedia/JZMediaAliyun.java +++ b/demo/src/main/java/cn/jzvd/demo/CustomMedia/JZMediaAliyun.java @@ -1,7 +1,10 @@ package cn.jzvd.demo.CustomMedia; +import android.content.Context; +import android.content.SharedPreferences; import android.graphics.SurfaceTexture; import android.os.Handler; +import android.text.TextUtils; import android.util.Log; import android.view.Surface; @@ -11,12 +14,12 @@ import com.aliyun.player.bean.ErrorInfo; import com.aliyun.player.bean.InfoBean; import com.aliyun.player.bean.InfoCode; +import com.aliyun.player.nativeclass.CacheConfig; import com.aliyun.player.nativeclass.PlayerConfig; import com.aliyun.player.source.UrlSource; import cn.jzvd.JZMediaInterface; import cn.jzvd.Jzvd; -import cn.jzvd.demo.ApplicationDemo; /** * usage: 阿里云播放器内核 @@ -29,6 +32,8 @@ public class JZMediaAliyun extends JZMediaInterface implements IPlayer.OnPrepare private static final String TAG = JZMediaAliyun.class.getSimpleName(); private static final int FROM_ALIYUN_PLAYER_INFO = 0x1688; + public static String AliyunVideoCachePath = ""; + private int initialRotation = -1; // 视频首次播放时的初始角度 fix阿里云上传功能 缓存导致的方向改变问题 AliPlayer aliyunMediaPlayer; private boolean isPlaying; @@ -59,10 +64,15 @@ public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int hei @Override public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { + if (aliyunMediaPlayer != null) + aliyunMediaPlayer.redraw(); } @Override public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { + // 如果不支持全屏播放 建议增加下方代码 +// if (aliyunMediaPlayer != null) +// aliyunMediaPlayer.setDisplay(null); return false; } @@ -104,6 +114,22 @@ public void prepare() { aliyunMediaPlayer.setConfig(config); //endregion + //region 缓存功能 + if (!TextUtils.isEmpty(AliyunVideoCachePath)) { + CacheConfig cacheConfig = new CacheConfig(); + //开启缓存功能 + cacheConfig.mEnable = true; + //能够缓存的单个文件最大时长。超过此长度则不缓存 + cacheConfig.mMaxDurationS = 500; + //缓存目录的位置 + cacheConfig.mDir = AliyunVideoCachePath; + //缓存目录的最大大小。超过此大小,将会删除最旧的缓存文件 + cacheConfig.mMaxSizeMB = 200; + //设置缓存配置给到播放器 + aliyunMediaPlayer.setCacheConfig(cacheConfig); + } + //endregion + // aliyunMediaPlayer.setAutoPlay(true); // 是否自动播放 // aliyunMediaPlayer.setLoop(true); // 是否循环播放 @@ -118,6 +144,14 @@ public void prepare() { aliyunMediaPlayer.setOnLoadingStatusListener(JZMediaAliyun.this); //endregion + // aliYun 播放器展示模式与Jzvd展示兼容 可通过jzDataSource传参修改 + if (jzvd.jzDataSource.objects != null) { + Jzvd.setVideoImageDisplayType((Integer) jzvd.jzDataSource.objects[0]); + } else { + Jzvd.setVideoImageDisplayType(Jzvd.VIDEO_IMAGE_DISPLAY_TYPE_FILL_SCROP); // 默认剪裁模式 + } + aliyunMediaPlayer.setScaleMode(IPlayer.ScaleMode.SCALE_ASPECT_FIT); // 设置模式为fit适应 + //设置配置给播放器 try { // 创建DataSource,准备播放 可通过jzDataSource区分是否加密 @@ -213,6 +247,24 @@ public void onPrepared() { @Override public void onVideoSizeChanged(int i, int i1) { + if (aliyunMediaPlayer != null && !TextUtils.isEmpty(AliyunVideoCachePath)) { + // FIXME: 2020/10/19 解决问题: 在播放网络视频时 能拿到视频的旋转角度正常播放, 在播放缓存的视频时 角度为0 播放方向异常, 需要转换为初始网络视频的角度, 因此对角度进行缓存 如果视频角度发生变化, 旋转为初始网络视频记录的角度 + if (initialRotation == -1) { // 视频开始播放时 + if (getCacheRotation(jzvd.jzDataSource.getCurrentUrl()) == -1) { // 没进行过角度的缓存 说明是第一次播放 + Log.d(TAG, "第一次播放, 记录角度:" + aliyunMediaPlayer.getVideoRotation()); + initialRotation = aliyunMediaPlayer.getVideoRotation(); + saveCacheRotation(jzvd.jzDataSource.getCurrentUrl(), aliyunMediaPlayer.getVideoRotation());// 缓存旋转角度 + } else { // 说明不是第一次播放, 直接取缓存的角度 + Log.d(TAG, "第一次播放, 获取角度:" + getCacheRotation(jzvd.jzDataSource.getCurrentUrl())); + initialRotation = getCacheRotation(jzvd.jzDataSource.getCurrentUrl()); + } + } + + if (initialRotation != aliyunMediaPlayer.getVideoRotation()) { // 如果当前角度与初始化角度不同, 应使用初始化角度 + Log.d(TAG, "角度应旋转:" + initialRotation); + Jzvd.setTextureViewRotation(initialRotation); + } + } handler.post(() -> jzvd.onVideoSizeChanged(aliyunMediaPlayer.getVideoWidth(), aliyunMediaPlayer.getVideoHeight())); } @@ -274,4 +326,21 @@ public void onLoadingProgress(int percent, float kbps) { public void onLoadingEnd() { //缓冲结束 } + + public void saveCacheRotation(Object url, int rotation) { + if (jzvd == null) + return; + SharedPreferences spn = jzvd.getContext().getSharedPreferences("ALIYUN_ROTATION", + Context.MODE_PRIVATE); + SharedPreferences.Editor editor = spn.edit(); + editor.putInt("rotate:" + url.toString(), rotation).apply(); + } + + public int getCacheRotation(Object url) { + if (jzvd == null) + return -1; + SharedPreferences spn = jzvd.getContext().getSharedPreferences("ALIYUN_ROTATION", + Context.MODE_PRIVATE); + return spn.getInt("rotate:" + url.toString(), -1); + } } diff --git a/demo/src/main/java/cn/jzvd/demo/Fragment_1_Base.java b/demo/src/main/java/cn/jzvd/demo/Fragment_1_Base.java index d6449a74..80adab8e 100644 --- a/demo/src/main/java/cn/jzvd/demo/Fragment_1_Base.java +++ b/demo/src/main/java/cn/jzvd/demo/Fragment_1_Base.java @@ -8,12 +8,15 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Button; +import android.widget.Toast; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import com.bumptech.glide.Glide; +import org.jzvd.jzvideo.UrlsKt; + import java.util.LinkedHashMap; import cn.jzvd.JZDataSource; @@ -21,7 +24,6 @@ import cn.jzvd.Jzvd; import cn.jzvd.JzvdStd; import cn.jzvd.demo.Tab_1_Basic.CustomMediaActivity; -import cn.jzvd.demo.Tab_1_Basic.ExtendsNormalActivity; import cn.jzvd.demo.Tab_1_Basic.OrientationActivity; import cn.jzvd.demo.Tab_1_Basic.PreloadingActivity; import cn.jzvd.demo.Tab_1_Basic.RotationVideoSizeActivity; @@ -36,29 +38,32 @@ public class Fragment_1_Base extends Fragment implements View.OnClickListener { private JzvdStd mJzvdStd; - private Button mOrientation, mExtendsNormalActivity, + private Button mOrientation, mRotationAndVideoSize, mCustomMediaPlayer, mPreLoading, mScreenRotate; + private Button serverCn, serverUs; private Jzvd.JZAutoFullscreenListener mSensorEventListener; private SensorManager mSensorManager; @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = View.inflate(getContext(), R.layout.fragment_api, null); + View view = View.inflate(getContext(), R.layout.fragment_base, null); mJzvdStd = view.findViewById(R.id.jz_video); mOrientation = view.findViewById(R.id.orientation); - mExtendsNormalActivity = view.findViewById(R.id.extends_normal_activity); mRotationAndVideoSize = view.findViewById(R.id.rotation_and_videosize); mCustomMediaPlayer = view.findViewById(R.id.custom_mediaplayer); mPreLoading = view.findViewById(R.id.preloading); mScreenRotate = view.findViewById(R.id.screen_rotate); + serverCn = view.findViewById(R.id.server_cn); + serverUs = view.findViewById(R.id.server_us); mOrientation.setOnClickListener(this); - mExtendsNormalActivity.setOnClickListener(this); mRotationAndVideoSize.setOnClickListener(this); mCustomMediaPlayer.setOnClickListener(this); mPreLoading.setOnClickListener(this); mScreenRotate.setOnClickListener(this); + serverCn.setOnClickListener(this); + serverUs.setOnClickListener(this); mSensorManager = (SensorManager) getContext().getSystemService(SENSOR_SERVICE); mSensorEventListener = new Jzvd.JZAutoFullscreenListener(); @@ -71,17 +76,18 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); LinkedHashMap map = new LinkedHashMap(); - String proxyUrl = ApplicationDemo.getProxy(getContext()).getProxyUrl(Urls.clarities[0]); + String proxyUrl = ApplicationDemo.getProxy(getContext()).getProxyUrl(UrlsKt.getCndVideos()[0]); map.put("高清", proxyUrl); - map.put("标清", Urls.clarities[1]); - map.put("普清", Urls.clarities[2]); - JZDataSource jzDataSource = new JZDataSource(map, "饺子不信"); + map.put("标清", UrlsKt.getCndVideos()[1]); + map.put("普清", UrlsKt.getCndVideos()[2]); + JZDataSource jzDataSource = new JZDataSource(map, "饺子起立"); jzDataSource.looping = true; jzDataSource.currentUrlIndex = 2; jzDataSource.headerMap.put("key", "value");//header mJzvdStd.setUp(jzDataSource , JzvdStd.SCREEN_NORMAL); - Glide.with(this).load(Urls.videoPosterList[0]).into(mJzvdStd.posterImageView); + Jzvd.PROGRESS_DRAG_RATE = 2f;//设置播放进度条手势滑动阻尼系数 + Glide.with(this).load(UrlsKt.getCndThumbnail()[0]).into(mJzvdStd.posterImageView); } @@ -109,9 +115,6 @@ public void onClick(View view) { case R.id.orientation: startActivity(new Intent(getContext(), OrientationActivity.class)); break; - case R.id.extends_normal_activity: - startActivity(new Intent(getContext(), ExtendsNormalActivity.class)); - break; case R.id.rotation_and_videosize: startActivity(new Intent(getContext(), RotationVideoSizeActivity.class)); break; @@ -124,7 +127,14 @@ public void onClick(View view) { case R.id.screen_rotate: startActivity(new Intent(getContext(), ScreenRotateActivity.class)); break; - + case R.id.server_cn: + UrlsKt.setServer_name(UrlsKt.getCn()); + Toast.makeText(getContext(), "change server to: " + UrlsKt.getCn(), Toast.LENGTH_SHORT).show(); + break; + case R.id.server_us: + UrlsKt.setServer_name(UrlsKt.getUs()); + Toast.makeText(getContext(), "change server to: " + UrlsKt.getUs(), Toast.LENGTH_SHORT).show(); + break; } } } diff --git a/demo/src/main/java/cn/jzvd/demo/Fragment_2_Custom.java b/demo/src/main/java/cn/jzvd/demo/Fragment_2_Custom.java index 46de9f8f..17624e1c 100644 --- a/demo/src/main/java/cn/jzvd/demo/Fragment_2_Custom.java +++ b/demo/src/main/java/cn/jzvd/demo/Fragment_2_Custom.java @@ -12,8 +12,12 @@ import com.bumptech.glide.Glide; +import org.jzvd.jzvideo.UrlsKt; + import cn.jzvd.Jzvd; import cn.jzvd.JzvdStd; +import cn.jzvd.demo.CustomJzvd.JzvdStdAutoOrizental; +import cn.jzvd.demo.CustomJzvd.JzvdStdRound; import cn.jzvd.demo.Tab_2_Custom.AGVideo.AGVideoActivity; import cn.jzvd.demo.CustomJzvd.JzvdStdAutoCompleteAfterFullscreen; import cn.jzvd.demo.CustomJzvd.JzvdStdLockScreen; @@ -40,6 +44,8 @@ public class Fragment_2_Custom extends Fragment implements View.OnClickListener JzvdStdSpeed jzvdStdSpeed; JzvdStdLockScreen lockScreen; JzvdStdVolume jzvdStdVolume; + JzvdStdRound jzvdStdRound; + JzvdStdAutoOrizental jzvdStdAutoOrizental; JzvdStd jzvdStd_1_1, jzvdStd_16_9; JzvdStd jzNoTitle; @@ -53,6 +59,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa agVideo = view.findViewById(R.id.agvideo); jzNoTitle = view.findViewById(R.id.jz_notitle); lockScreen = view.findViewById(R.id.lock_screen); + jzvdStdRound = view.findViewById(R.id.jz_round); jzvdStdWithShareButton = view.findViewById(R.id.custom_videoplayer_standard_with_share_button); jzvdStdShowTitleAfterFullscreen = view.findViewById(R.id.custom_videoplayer_standard_show_title_after_fullscreen); jzvdStdShowTextureViewAfterAutoComplete = view.findViewById(R.id.custom_videoplayer_standard_show_textureview_aoto_complete); @@ -63,6 +70,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa jzvdStdMp3 = view.findViewById(R.id.jz_videoplayer_mp3); jzvdStdSpeed = view.findViewById(R.id.jz_videoplayer_speed); jzvdStdVolume = view.findViewById(R.id.custom_videoplayer_standard_with_volume_button); + jzvdStdAutoOrizental = view.findViewById(R.id.jz_auto_oriental); agVideo.setOnClickListener(this); return view; @@ -72,76 +80,56 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); + jzvdStdAutoOrizental.setUp(UrlsKt.getVideos()[0], UrlsKt.getTitles()[0]); + Glide.with(this).load(UrlsKt.getThumbnails()[0]).into(jzvdStdAutoOrizental.posterImageView); + + jzvdStdRound.setUp(UrlsKt.getVideos()[1], UrlsKt.getTitles()[1]); + Glide.with(this).load(UrlsKt.getThumbnails()[1]).into(jzvdStdRound.posterImageView); - jzNoTitle.setUp("http://jzvd.nathen.cn/342a5f7ef6124a4a8faf00e738b8bee4/cf6d9db0bd4d41f59d09ea0a81e918fd-5287d2089db37e62345123a1be272f8b.mp4" - , "饺子叫啥也显示不出来啊"); - Glide.with(this).load("http://jzvd-pic.nathen.cn/jzvd-pic/1bb2ebbe-140d-4e2e-abd2-9e7e564f71ac.png").into(jzNoTitle.posterImageView); + jzNoTitle.setUp(UrlsKt.getVideos()[2], UrlsKt.getTitles()[2]); + Glide.with(this).load(UrlsKt.getThumbnails()[2]).into(jzNoTitle.posterImageView); - lockScreen.setUp("http://jzvd.nathen.cn/342a5f7ef6124a4a8faf00e738b8bee4/cf6d9db0bd4d41f59d09ea0a81e918fd-5287d2089db37e62345123a1be272f8b.mp4" - , "饺子定身"); - Glide.with(this).load("http://jzvd-pic.nathen.cn/jzvd-pic/1bb2ebbe-140d-4e2e-abd2-9e7e564f71ac.png").into(lockScreen.posterImageView); + lockScreen.setUp(UrlsKt.getVideos()[3], UrlsKt.getTitles()[3]); + Glide.with(this).load(UrlsKt.getThumbnails()[3]).into(lockScreen.posterImageView); - jzvdStdWithShareButton.setUp(Urls.videoUrlList[3], "饺子想呼吸", Jzvd.SCREEN_NORMAL); - Glide.with(this) - .load(Urls.videoPosterList[3]) - .into(jzvdStdWithShareButton.posterImageView); + jzvdStdWithShareButton.setUp(UrlsKt.getVideos()[4], UrlsKt.getTitles()[4], Jzvd.SCREEN_NORMAL); + Glide.with(this).load(UrlsKt.getThumbnails()[4]).into(jzvdStdWithShareButton.posterImageView); - jzvdStdShowTitleAfterFullscreen.setUp(Urls.videoUrlList[4], "饺子想摇头", Jzvd.SCREEN_NORMAL); - Glide.with(this) - .load(Urls.videoPosterList[4]) - .into(jzvdStdShowTitleAfterFullscreen.posterImageView); + jzvdStdShowTitleAfterFullscreen.setUp(UrlsKt.getVideos()[5], UrlsKt.getTitles()[5], Jzvd.SCREEN_NORMAL); + Glide.with(this).load(UrlsKt.getThumbnails()[5]).into(jzvdStdShowTitleAfterFullscreen.posterImageView); - jzvdStdShowTextureViewAfterAutoComplete.setUp(Urls.videoUrlList[5], "饺子想旅行", Jzvd.SCREEN_NORMAL); - Glide.with(this) - .load(Urls.videoPosterList[5]) - .into(jzvdStdShowTextureViewAfterAutoComplete.posterImageView); + jzvdStdShowTextureViewAfterAutoComplete.setUp(UrlsKt.getVideos()[6], UrlsKt.getTitles()[6], Jzvd.SCREEN_NORMAL); + Glide.with(this).load(UrlsKt.getThumbnails()[6]).into(jzvdStdShowTextureViewAfterAutoComplete.posterImageView); - jzvdStdAutoCompleteAfterFullscreen.setUp(Urls.videoUrls[0][1], "饺子没来", Jzvd.SCREEN_NORMAL); - Glide.with(this) - .load(Urls.videoPosters[0][1]) - .into(jzvdStdAutoCompleteAfterFullscreen.posterImageView); + jzvdStdAutoCompleteAfterFullscreen.setUp(UrlsKt.getVideos()[7], UrlsKt.getTitles()[7], Jzvd.SCREEN_NORMAL); + Glide.with(this).load(UrlsKt.getThumbnails()[7]).into(jzvdStdAutoCompleteAfterFullscreen.posterImageView); - jzvdStd_1_1.setUp(Urls.videoUrls[0][1], "饺子有事吗", Jzvd.SCREEN_NORMAL); - Glide.with(this) - .load(Urls.videoPosters[0][1]) - .into(jzvdStd_1_1.posterImageView); + jzvdStd_1_1.setUp(UrlsKt.getVideos()[8], UrlsKt.getTitles()[8], Jzvd.SCREEN_NORMAL); + Glide.with(this).load(UrlsKt.getThumbnails()[8]).into(jzvdStd_1_1.posterImageView); jzvdStd_1_1.widthRatio = 1; jzvdStd_1_1.heightRatio = 1; - jzvdStd_16_9.setUp(Urls.videoUrls[0][1], "饺子来不了", Jzvd.SCREEN_NORMAL); - Glide.with(this) - .load(Urls.videoPosters[0][1]) - .into(jzvdStd_16_9.posterImageView); + jzvdStd_16_9.setUp(UrlsKt.getVideos()[9], UrlsKt.getTitles()[9], Jzvd.SCREEN_NORMAL); + Glide.with(this).load(UrlsKt.getThumbnails()[9]).into(jzvdStd_16_9.posterImageView); jzvdStd_16_9.widthRatio = 16; jzvdStd_16_9.heightRatio = 9; - jzvdStdVolumeAfterFullscreen.setUp(Urls.videoUrls[0][1], "饺子摇摆", Jzvd.SCREEN_NORMAL); - Glide.with(this) - .load(Urls.videoPosters[0][1]) - .into(jzvdStdVolumeAfterFullscreen.posterImageView); + jzvdStdVolumeAfterFullscreen.setUp(UrlsKt.getVideos()[10], UrlsKt.getTitles()[10], Jzvd.SCREEN_NORMAL); + Glide.with(this).load(UrlsKt.getThumbnails()[10]).into(jzvdStdVolumeAfterFullscreen.posterImageView); - jzvdStdMp3.setUp(Urls.videoUrls[0][1], - "饺子你听", Jzvd.SCREEN_NORMAL); - Glide.with(this) - .load(Urls.videoPosters[0][1]) - .into(jzvdStdMp3.posterImageView); + jzvdStdMp3.setUp(UrlsKt.getVideos()[11], UrlsKt.getTitles()[11], Jzvd.SCREEN_NORMAL); + Glide.with(this).load(UrlsKt.getThumbnails()[11]).into(jzvdStdMp3.posterImageView); - jzvdStdSpeed.setUp(Urls.videoUrls[0][1], - "饺子快点", Jzvd.SCREEN_NORMAL); - Glide.with(this) - .load(Urls.videoPosters[0][1]) - .into(jzvdStdSpeed.posterImageView); + jzvdStdSpeed.setUp(UrlsKt.getVideos()[12], UrlsKt.getTitles()[12], Jzvd.SCREEN_NORMAL); + Glide.with(this).load(UrlsKt.getThumbnails()[12]).into(jzvdStdSpeed.posterImageView); - jzvdStdVolume.setUp(Urls.videoUrls[0][1], - "饺子吃莽莽", Jzvd.SCREEN_NORMAL); - Glide.with(this) - .load(Urls.videoPosters[0][1]) - .into(jzvdStdVolume.posterImageView); + jzvdStdVolume.setUp(UrlsKt.getVideos()[13], UrlsKt.getTitles()[13], Jzvd.SCREEN_NORMAL); + Glide.with(this).load(UrlsKt.getThumbnails()[13]).into(jzvdStdVolume.posterImageView); } @Override diff --git a/demo/src/main/java/cn/jzvd/demo/Fragment_4_More.java b/demo/src/main/java/cn/jzvd/demo/Fragment_4_More.java index f6bc5394..c442e751 100644 --- a/demo/src/main/java/cn/jzvd/demo/Fragment_4_More.java +++ b/demo/src/main/java/cn/jzvd/demo/Fragment_4_More.java @@ -16,6 +16,7 @@ import cn.jzvd.demo.Tab_3_List.GetGifActivity; import cn.jzvd.demo.Tab_3_List.TinyWindow.TinyWindowActivity; +import cn.jzvd.demo.Tab_4_More.DanmuActivity; import cn.jzvd.demo.Tab_4_More.DirectPlayActivity; import cn.jzvd.demo.Tab_4_More.LocalVideoActivity; import cn.jzvd.demo.Tab_4_More.WebViewActivity; @@ -26,7 +27,7 @@ public class Fragment_4_More extends Fragment implements View.OnClickListener { TextView versionTextView; - private Button mDirectPlay, mWebView, mLocalVideo, mTinyWindow, mGetGif; + private Button mDirectPlay, mWebView, mLocalVideo, mTinyWindow, mGetGif,mDanmu; public static String getAppVersionName(Context context) { String appVersionName = ""; @@ -52,6 +53,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa versionTextView = view.findViewById(R.id.version); mTinyWindow = view.findViewById(R.id.tiny_window); mGetGif = view.findViewById(R.id.get_gif); + mDanmu = view.findViewById(R.id.danmu_view); mDirectPlay.setOnClickListener(this); @@ -59,6 +61,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa mLocalVideo.setOnClickListener(this); mGetGif.setOnClickListener(this); mTinyWindow.setOnClickListener(this); + mDanmu.setOnClickListener(this); return view; } @@ -87,6 +90,9 @@ public void onClick(View view) { case R.id.get_gif: startActivity(new Intent(getContext(), GetGifActivity.class)); break; + case R.id.danmu_view: + startActivity(new Intent(getContext(), DanmuActivity.class)); + break; } } diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/CustomMediaActivity.java b/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/CustomMediaActivity.java index 4fe9ddc4..7777dc74 100644 --- a/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/CustomMediaActivity.java +++ b/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/CustomMediaActivity.java @@ -10,6 +10,8 @@ import com.bumptech.glide.Glide; +import org.jzvd.jzvideo.UrlsKt; + import cn.jzvd.JZMediaSystem; import cn.jzvd.Jzvd; import cn.jzvd.JzvdStd; @@ -37,11 +39,11 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { jzvdStd = findViewById(R.id.videoplayer); - jzvdStd.setUp("http://jzvd.nathen.cn/342a5f7ef6124a4a8faf00e738b8bee4/cf6d9db0bd4d41f59d09ea0a81e918fd-5287d2089db37e62345123a1be272f8b.mp4" - , "饺子很保守", JzvdStd.SCREEN_NORMAL); + jzvdStd.setUp(UrlsKt.getVideos()[9] + , UrlsKt.getTitles()[9], JzvdStd.SCREEN_NORMAL); Glide.with(this) - .load("http://jzvd-pic.nathen.cn/jzvd-pic/1bb2ebbe-140d-4e2e-abd2-9e7e564f71ac.png") + .load(UrlsKt.getThumbnails()[9]) .into(jzvdStd.posterImageView); } @@ -49,32 +51,31 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { public void clickChangeToIjkplayer(View view) { Jzvd.releaseAllVideos(); - jzvdStd.setUp("http://jzvd.nathen.cn/342a5f7ef6124a4a8faf00e738b8bee4/cf6d9db0bd4d41f59d09ea0a81e918fd-5287d2089db37e62345123a1be272f8b.mp4" - , "饺子变心", JzvdStd.SCREEN_NORMAL, JZMediaIjk.class); + jzvdStd.setUp(UrlsKt.getVideos()[1] + , UrlsKt.getTitles()[1], JzvdStd.SCREEN_NORMAL, JZMediaIjk.class); jzvdStd.startVideo(); Toast.makeText(this, "Change to Ijkplayer", Toast.LENGTH_SHORT).show(); } public void clickChangeToSystem(View view) { Jzvd.releaseAllVideos(); - jzvdStd.setUp("http://jzvd.nathen.cn/342a5f7ef6124a4a8faf00e738b8bee4/cf6d9db0bd4d41f59d09ea0a81e918fd-5287d2089db37e62345123a1be272f8b.mp4" - , "饺子回来了", JzvdStd.SCREEN_NORMAL, JZMediaSystem.class); + jzvdStd.setUp(UrlsKt.getVideos()[1] + , UrlsKt.getTitles()[1], JzvdStd.SCREEN_NORMAL, JZMediaSystem.class); jzvdStd.startVideo(); Toast.makeText(this, "Change to MediaPlayer", Toast.LENGTH_SHORT).show(); } public void clickChangeToExo(View view) { Jzvd.releaseAllVideos(); - jzvdStd.setUp("http://jzvd.nathen.cn/342a5f7ef6124a4a8faf00e738b8bee4/cf6d9db0bd4d41f59d09ea0a81e918fd-5287d2089db37e62345123a1be272f8b.mp4" - , "饺子追星", JzvdStd.SCREEN_NORMAL, JZMediaExo.class); + jzvdStd.setUp(UrlsKt.getVideos()[1] + , UrlsKt.getTitles()[1], JzvdStd.SCREEN_NORMAL, JZMediaExo.class); jzvdStd.startVideo(); Toast.makeText(this, "Change to ExoPlayer", Toast.LENGTH_SHORT).show(); } public void clickChangeToAliyun(View view) { Jzvd.releaseAllVideos(); - jzvdStd.setUp("http://jzvd.nathen.cn/342a5f7ef6124a4a8faf00e738b8bee4/cf6d9db0bd4d41f59d09ea0a81e918fd-5287d2089db37e62345123a1be272f8b.mp4" - , "饺子梭哈", JzvdStd.SCREEN_NORMAL, JZMediaAliyun.class); + jzvdStd.setMediaInterface(JZMediaAliyun.class); jzvdStd.startVideo(); Toast.makeText(this, "Change to AliyunPlayer", Toast.LENGTH_SHORT).show(); } diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/ExtendsNormalActivity.java b/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/ExtendsNormalActivity.java deleted file mode 100644 index 98ba149e..00000000 --- a/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/ExtendsNormalActivity.java +++ /dev/null @@ -1,44 +0,0 @@ -package cn.jzvd.demo.Tab_1_Basic; - -import android.app.Activity; -import android.os.Bundle; - -import com.bumptech.glide.Glide; - -import cn.jzvd.Jzvd; -import cn.jzvd.JzvdStd; -import cn.jzvd.demo.R; -import cn.jzvd.demo.Urls; - -/** - * 适配了普通的Activity,如果不适配并且不继承AppCompatActivity的话会出现Context空指针的情况 - * Created by Nathen on 2017/9/19. - */ -public class ExtendsNormalActivity extends Activity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_extends_normal); - JzvdStd jzvdStd = findViewById(R.id.videoplayer); - jzvdStd.setUp(Urls.videoUrlList[0], "饺子不信" - , JzvdStd.SCREEN_NORMAL); - Glide.with(this) - .load(Urls.videoPosterList[0]) - .into(jzvdStd.posterImageView); - } - - @Override - public void onBackPressed() { - if (Jzvd.backPress()) { - return; - } - super.onBackPressed(); - } - - @Override - protected void onPause() { - super.onPause(); - Jzvd.releaseAllVideos(); - } -} diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/OrientationActivity.java b/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/OrientationActivity.java index c74928ce..9cb76489 100644 --- a/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/OrientationActivity.java +++ b/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/OrientationActivity.java @@ -9,10 +9,11 @@ import com.bumptech.glide.Glide; +import org.jzvd.jzvideo.UrlsKt; + import cn.jzvd.Jzvd; import cn.jzvd.JzvdStd; import cn.jzvd.demo.R; -import cn.jzvd.demo.Urls; /** * Created by Nathen on 2016/12/30. @@ -30,10 +31,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { getSupportActionBar().setTitle(getString(R.string.orientation)); setContentView(R.layout.activity_orientation); mJzvdStd = findViewById(R.id.jz_video); - mJzvdStd.setUp(Urls.videoUrlList[0], "饺子会旋转" + mJzvdStd.setUp(UrlsKt.getVideos()[25], UrlsKt.getTitles()[25] , JzvdStd.SCREEN_NORMAL); Glide.with(this) - .load(Urls.videoPosterList[0]) + .load(UrlsKt.getThumbnails()[25]) .into(mJzvdStd.posterImageView); } @@ -41,7 +42,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onResume() { super.onResume(); Jzvd.FULLSCREEN_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; - Jzvd.NORMAL_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; + Jzvd.NORMAL_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; } @Override diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/PreloadingActivity.java b/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/PreloadingActivity.java index ddb9b24b..6365e1cd 100644 --- a/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/PreloadingActivity.java +++ b/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/PreloadingActivity.java @@ -8,6 +8,8 @@ import com.bumptech.glide.Glide; +import org.jzvd.jzvideo.UrlsKt; + import cn.jzvd.Jzvd; import cn.jzvd.JzvdStd; import cn.jzvd.demo.CustomMedia.JZMediaIjk; @@ -28,17 +30,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { setContentView(R.layout.activity_preloading); jzvdStd = findViewById(R.id.jz_video); -// jzvdStd.setUp("http://jzvd.nathen.cn/342a5f7ef6124a4a8faf00e738b8bee4/cf6d9db0bd4d41f59d09ea0a81e918fd-5287d2089db37e62345123a1be272f8b.mp4" -// , "饺子快长大", Jzvd.SCREEN_NORMAL, JZMediaIjk.class); - jzvdStd.setUp("http://jzvd.nathen.cn/4f965ad507ef4194a60a943a34cfe147/32af151ea132471f92c9ced2cff785ea-5287d2089db37e62345123a1be272f8b.mp4" - , "饺子存钱", Jzvd.SCREEN_NORMAL, JZMediaIjk.class); - - -// jzvdStd.setUp("http://jzvd.nathen.cn/342a5f7ef6124a4a8faf00e738b8bee4/cf6d9db0bd4d41f59d09ea0a81e918fd-5287d2089db37e62345123a1be272f8b.mp4" -// , "饺子快长大"); -// jzvdStd.setUp("http://jzvd.nathen.cn/4f965ad507ef4194a60a943a34cfe147/32af151ea132471f92c9ced2cff785ea-5287d2089db37e62345123a1be272f8b.mp4" -// , "饺子快长大"); - Glide.with(this).load("http://jzvd-pic.nathen.cn/jzvd-pic/1bb2ebbe-140d-4e2e-abd2-9e7e564f71ac.png").into(jzvdStd.posterImageView); + jzvdStd.setUp(UrlsKt.getTitles()[7] + , UrlsKt.getTitles()[7], Jzvd.SCREEN_NORMAL, JZMediaIjk.class); + + Glide.with(this).load(UrlsKt.getTitles()[7]).into(jzvdStd.posterImageView); } diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/RotationVideoSizeActivity.java b/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/RotationVideoSizeActivity.java index 83715dac..21959946 100644 --- a/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/RotationVideoSizeActivity.java +++ b/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/RotationVideoSizeActivity.java @@ -9,10 +9,11 @@ import com.bumptech.glide.Glide; +import org.jzvd.jzvideo.UrlsKt; + import cn.jzvd.Jzvd; import cn.jzvd.JzvdStd; import cn.jzvd.demo.R; -import cn.jzvd.demo.Urls; /** * Created by Nathen on 2017/11/2. @@ -33,10 +34,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { setContentView(R.layout.activity_api_rotation_videosize); myJzvdStd = findViewById(R.id.jz_video); - myJzvdStd.setUp(Urls.videoUrls[0][7], Urls.videoTitles[0][7] + myJzvdStd.setUp(UrlsKt.getVideos()[30], UrlsKt.getTitles()[30] , JzvdStd.SCREEN_NORMAL); Glide.with(this) - .load(Urls.videoPosters[0][7]) + .load(UrlsKt.getThumbnails()[30]) .into(myJzvdStd.posterImageView); // The Point IS 或者这样写也可以 // myJzvdStd.videoRotation = 180; diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/ScreenRotateActivity.java b/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/ScreenRotateActivity.java index b83c304d..ae30b3a0 100644 --- a/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/ScreenRotateActivity.java +++ b/demo/src/main/java/cn/jzvd/demo/Tab_1_Basic/ScreenRotateActivity.java @@ -8,10 +8,11 @@ import com.bumptech.glide.Glide; +import org.jzvd.jzvideo.UrlsKt; + import cn.jzvd.Jzvd; import cn.jzvd.JzvdStd; import cn.jzvd.demo.R; -import cn.jzvd.demo.Urls; import cn.jzvd.demo.utils.ScreenRotateUtils; /** @@ -30,10 +31,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { getSupportActionBar().setTitle(getString(R.string.screen_rotate)); setContentView(R.layout.activity_screen_rotate); mJzvdStd = findViewById(R.id.jz_video); - mJzvdStd.setUp(Urls.videoUrlList[0], "饺子挺好" + mJzvdStd.setUp(UrlsKt.getVideos()[16], UrlsKt.getTitles()[16] , JzvdStd.SCREEN_NORMAL); Glide.with(this) - .load(Urls.videoPosterList[0]) + .load(UrlsKt.getThumbnails()[16]) .into(mJzvdStd.posterImageView); ScreenRotateUtils.getInstance(this.getApplicationContext()).setOrientationChangeListener(this); } diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_2_Custom/AGVideo/AGVideo.java b/demo/src/main/java/cn/jzvd/demo/Tab_2_Custom/AGVideo/AGVideo.java index c0ee7957..04dc8100 100644 --- a/demo/src/main/java/cn/jzvd/demo/Tab_2_Custom/AGVideo/AGVideo.java +++ b/demo/src/main/java/cn/jzvd/demo/Tab_2_Custom/AGVideo/AGVideo.java @@ -163,6 +163,7 @@ public void onClick(View v) { onStatePause(); } else if (state == STATE_PAUSE) { mediaInterface.start(); + onStatePlaying(); } else if (state == STATE_AUTO_COMPLETE) { startVideo(); } @@ -260,8 +261,10 @@ public void onClick(View v) { //点击重播,取消下一集倒计时 dismissNextView(); cancelDismissNextViewTimer(); - resetProgressAndTime(); - mediaInterface.seekTo(0); + + //resetProgressAndTime(); + //mediaInterface.seekTo(0); + changeUrl(jzDataSource, 0); } break; case R.id.next_set: diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_2_Custom/AGVideo/AGVideoActivity.java b/demo/src/main/java/cn/jzvd/demo/Tab_2_Custom/AGVideo/AGVideoActivity.java index 99823336..2f0d0e11 100644 --- a/demo/src/main/java/cn/jzvd/demo/Tab_2_Custom/AGVideo/AGVideoActivity.java +++ b/demo/src/main/java/cn/jzvd/demo/Tab_2_Custom/AGVideo/AGVideoActivity.java @@ -6,22 +6,22 @@ import android.widget.TextView; import android.widget.Toast; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; - import com.google.android.material.tabs.TabLayout; +import org.jzvd.jzvideo.UrlsKt; + import java.util.ArrayList; import java.util.List; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; import cn.jzvd.JZDataSource; import cn.jzvd.Jzvd; import cn.jzvd.JzvdStd; -import cn.jzvd.demo.Tab_2_Custom.AGVideo.popup.VideoEpisodePopup; -import cn.jzvd.demo.Tab_2_Custom.AGVideo.popup.VideoSpeedPopup; import cn.jzvd.demo.CustomMedia.JZMediaExo; import cn.jzvd.demo.R; -import cn.jzvd.demo.Urls; +import cn.jzvd.demo.Tab_2_Custom.AGVideo.popup.VideoEpisodePopup; +import cn.jzvd.demo.Tab_2_Custom.AGVideo.popup.VideoSpeedPopup; import cn.jzvd.demo.utils.ScreenRotateUtils; public class AGVideoActivity extends AppCompatActivity implements AGVideo.JzVideoListener, ScreenRotateUtils.OrientationChangeListener @@ -234,7 +234,7 @@ private void dismissSpeedPopAndEpisodePop() { * @param speed */ private void changeSpeed(float speed) { - Object[] object = {speed}; + Object[] object = { speed }; mPlayer.mediaInterface.setSpeed(speed); mJzDataSource.objects[0] = object; Toast.makeText(this, "正在以" + speed + "X倍速播放", Toast.LENGTH_SHORT).show(); @@ -285,7 +285,7 @@ public void selectPartsClick() { videoEpisodePopup = new VideoEpisodePopup(this, episodeList); videoEpisodePopup.setEpisondeClickListener(this); } - videoEpisodePopup.setPlayNum(1); + videoEpisodePopup.setPlayNum(episodes.getSelectedTabPosition() + 1); videoEpisodePopup.showAtLocation(getWindow().getDecorView(), Gravity.RIGHT, 0, 0); } @@ -314,10 +314,8 @@ public void onEpisodeClickListener(AGEpsodeEntity entity, int position) { private void initVideoData() { episodeList = new ArrayList<>(); - for (int i = 0; i < Urls.ssVideos.length; i++) { - episodeList.add(new AGEpsodeEntity(Urls.ssVideos[i], "三生三世枕上书 第" + (i + 1) + "集")); + for (int i = 0; i < UrlsKt.getLdjVideos().length; i++) { + episodeList.add(new AGEpsodeEntity(UrlsKt.getLdjVideos()[i], "鹿鼎记 第" + (i + 1) + "集")); } } - - } diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_2_Custom/AGVideo/popup/VideoEpisodePopup.java b/demo/src/main/java/cn/jzvd/demo/Tab_2_Custom/AGVideo/popup/VideoEpisodePopup.java index aea9f533..162bec66 100644 --- a/demo/src/main/java/cn/jzvd/demo/Tab_2_Custom/AGVideo/popup/VideoEpisodePopup.java +++ b/demo/src/main/java/cn/jzvd/demo/Tab_2_Custom/AGVideo/popup/VideoEpisodePopup.java @@ -11,16 +11,15 @@ import android.widget.LinearLayout; import android.widget.PopupWindow; -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - import java.util.List; import java.util.Timer; import java.util.TimerTask; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import cn.jzvd.demo.R; import cn.jzvd.demo.Tab_2_Custom.AGVideo.AGEpsodeEntity; import cn.jzvd.demo.Tab_2_Custom.AGVideo.VideoEpisodeAdapter; -import cn.jzvd.demo.R; import cn.jzvd.demo.utils.DipAndPx; public class VideoEpisodePopup extends PopupWindow { @@ -130,6 +129,8 @@ public void setPlayNum(int playNum) { this.playNum = playNum; episodeList.get(this.playNum - 1).setPlay(true); } + + episodeRecycler.getAdapter().notifyDataSetChanged(); } public void startDismissTimer() { diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/GetGifActivity.java b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/GetGifActivity.java index 6e8518c5..054e7eb7 100644 --- a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/GetGifActivity.java +++ b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/GetGifActivity.java @@ -10,6 +10,8 @@ import com.bumptech.glide.Glide; +import org.jzvd.jzvideo.UrlsKt; + import java.util.LinkedHashMap; import cn.jzvd.JZDataSource; @@ -18,7 +20,6 @@ import cn.jzvd.demo.ApplicationDemo; import cn.jzvd.demo.CustomJzvd.JzvdStdGetGif; import cn.jzvd.demo.R; -import cn.jzvd.demo.Urls; /** * @author dl @@ -50,23 +51,17 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { jzvdStdGetGif = findViewById(R.id.jz_video); LinkedHashMap map = new LinkedHashMap(); - String proxyUrl = ApplicationDemo.getProxy(getBaseContext()).getProxyUrl(Urls.clarities[0]); + String proxyUrl = ApplicationDemo.getProxy(getBaseContext()).getProxyUrl("http://videos.jzvd.org/v/ldj/01-ldj.mp4"); map.put("高清", proxyUrl); - map.put("标清", Urls.clarities[1]); - map.put("普清", Urls.clarities[2]); - JZDataSource jzDataSource = new JZDataSource(map, "饺子会拼图"); + map.put("标清", "http://videos.jzvd.org/v/ldj/01-ldj.mp4"); + map.put("普清", "http://videos.jzvd.org/v/ldj/04-ldj.mp4"); + JZDataSource jzDataSource = new JZDataSource(map, "饺子不信"); jzDataSource.looping = true; jzDataSource.currentUrlIndex = 2; jzDataSource.headerMap.put("key", "value");//header - jzvdStdGetGif.setUp(jzDataSource - , JzvdStd.SCREEN_NORMAL); - Glide.with(this).load(Urls.videoPosterList[0]).into(jzvdStdGetGif.posterImageView); - - + jzvdStdGetGif.setUp(jzDataSource, JzvdStd.SCREEN_NORMAL); + Glide.with(this).load(UrlsKt.getThumbnails()[0]).into(jzvdStdGetGif.posterImageView); -// String url = "http://jzvd.nathen.cn/342a5f7ef6124a4a8faf00e738b8bee4/cf6d9db0bd4d41f59d09ea0a81e918fd-5287d2089db37e62345123a1be272f8b.mp4"; -// jzvdStdGetGif.setUp(url, "饺子会拼图"); -// Glide.with(this).load("http://jzvd-pic.nathen.cn/jzvd-pic/1bb2ebbe-140d-4e2e-abd2-9e7e564f71ac.png").into(jzvdStdGetGif.posterImageView); } @Override diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/FragmentDemo.java b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/FragmentDemo.java index debbbb14..e098885c 100644 --- a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/FragmentDemo.java +++ b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/FragmentDemo.java @@ -10,10 +10,11 @@ import androidx.fragment.app.Fragment; +import org.jzvd.jzvideo.UrlsKt; + import cn.jzvd.Jzvd; import cn.jzvd.demo.Tab_3_List.ListView.adapter.ListViewAdapter; import cn.jzvd.demo.R; -import cn.jzvd.demo.Urls; /** * Created by Nathen on 2017/6/9. @@ -38,9 +39,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInastanceState) { listView = (ListView) inflater.inflate(R.layout.layout_list, container, false); listView.setAdapter(new ListViewAdapter(getActivity(), - Urls.videoUrls[index], - Urls.videoTitles[index], - Urls.videoPosters[index])); + UrlsKt.getVll()[index], + UrlsKt.getTll()[index], + UrlsKt.getPll()[index])); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/ListViewMultiHolderActivity.java b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/ListViewMultiHolderActivity.java index 576561b1..f6917b71 100644 --- a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/ListViewMultiHolderActivity.java +++ b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/ListViewMultiHolderActivity.java @@ -15,10 +15,11 @@ import com.bumptech.glide.Glide; +import org.jzvd.jzvideo.UrlsKt; + import cn.jzvd.Jzvd; import cn.jzvd.JzvdStd; import cn.jzvd.demo.R; -import cn.jzvd.demo.Urls; /** * Created by Nathen @@ -132,11 +133,11 @@ public View getView(int position, View convertView, ViewGroup parent) { } viewHolder.jzvdStd.setUp( - Urls.videoUrls[0][position], - Urls.videoTitles[0][position], Jzvd.SCREEN_NORMAL); + UrlsKt.getVideos()[position], + UrlsKt.getTitles()[position], Jzvd.SCREEN_NORMAL); viewHolder.jzvdStd.positionInList = position; Glide.with(ListViewMultiHolderActivity.this) - .load(Urls.videoPosters[0][position]) + .load(UrlsKt.getThumbnails()[position]) .into(viewHolder.jzvdStd.posterImageView); } else { TextViewHolder textViewHolder; diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/NormalListViewActivity.java b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/NormalListViewActivity.java index b7d620de..afdb7c95 100644 --- a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/NormalListViewActivity.java +++ b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/NormalListViewActivity.java @@ -10,10 +10,11 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import org.jzvd.jzvideo.UrlsKt; + import cn.jzvd.Jzvd; import cn.jzvd.demo.Tab_3_List.ListView.adapter.ListViewAdapter; import cn.jzvd.demo.R; -import cn.jzvd.demo.Urls; /** * Created by Nathen on 16/7/31. @@ -36,9 +37,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { listView = findViewById(R.id.listview); listView.setAdapter(new ListViewAdapter(this, - Urls.videoUrls[0], - Urls.videoTitles[0], - Urls.videoPosters[0])); + UrlsKt.getVl2(), + UrlsKt.getTl2(), + UrlsKt.getPl2())); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/RecyclerViewActivity.java b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/RecyclerViewActivity.java index 9788823a..d9d7198b 100644 --- a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/RecyclerViewActivity.java +++ b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/RecyclerViewActivity.java @@ -4,21 +4,35 @@ import android.view.MenuItem; import android.view.View; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.scwang.smart.refresh.layout.SmartRefreshLayout; +import com.scwang.smart.refresh.layout.api.RefreshLayout; +import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener; +import com.scwang.smart.refresh.layout.listener.OnRefreshListener; + +import org.jzvd.jzvideo.UrlsKt; + +import java.util.ArrayList; +import java.util.Collections; + import cn.jzvd.Jzvd; -import cn.jzvd.demo.Tab_3_List.ListView.adapter.RecyclerViewAdapter; +import cn.jzvd.demo.Tab_3_List.ListView.adapter.RecyclerViewLoadMoreAdapter; import cn.jzvd.demo.R; +import cn.jzvd.demo.utils.VideoEntity; /** * Created by yujunkui on 16/8/29. */ public class RecyclerViewActivity extends AppCompatActivity { RecyclerView recyclerView; - RecyclerViewAdapter adapterVideoList; + RecyclerViewLoadMoreAdapter adapterVideoList; + SmartRefreshLayout refreshLayout; + ArrayList videos; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -30,11 +44,12 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { getSupportActionBar().setTitle(getString(R.string.recyclerview)); setContentView(R.layout.activity_recyclerview_content); - recyclerView = findViewById(R.id.recyclerview); - recyclerView.setLayoutManager(new LinearLayoutManager(this)); + initView(); + initData(); + initListener(); + } - adapterVideoList = new RecyclerViewAdapter(this); - recyclerView.setAdapter(adapterVideoList); + private void initListener() { recyclerView.addOnChildAttachStateChangeListener(new RecyclerView.OnChildAttachStateChangeListener() { @Override public void onChildViewAttachedToWindow(View view) { @@ -52,6 +67,81 @@ public void onChildViewDetachedFromWindow(View view) { } } }); + + refreshLayout.setOnRefreshListener(new OnRefreshListener() { + @Override + public void onRefresh(@NonNull RefreshLayout refreshLayout) { + loadData(); + } + }); + refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() { + @Override + public void onLoadMore(@NonNull RefreshLayout refreshLayout) { + loadMore(); + } + }); + + recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { + super.onScrollStateChanged(recyclerView, newState); + LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager(); + int lastPositon = linearLayoutManager.findLastVisibleItemPosition(); + int count = recyclerView.getAdapter().getItemCount(); + if (newState == RecyclerView.SCROLL_STATE_IDLE && count > 3 && lastPositon >= count - 3) { + loadMore(); + } + } + + @Override + public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { + super.onScrolled(recyclerView, dx, dy); + } + }); + } + + private void initView() { + refreshLayout = findViewById(R.id.refreshLayout); + recyclerView = findViewById(R.id.recyclerview); + } + + private void initData() { + videos = new ArrayList<>(); + addData(); + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + adapterVideoList = new RecyclerViewLoadMoreAdapter(this, videos); + recyclerView.setAdapter(adapterVideoList); + } + + private void addData() { + ArrayList tempList = new ArrayList<>(); + for (int i = 0; i < UrlsKt.getVl2().length; i++) { + VideoEntity videoEntity = new VideoEntity(); + videoEntity.setUrl(UrlsKt.getVl2()[i]); + videoEntity.setTitle(UrlsKt.getTl2()[i]); + videoEntity.setThumb(UrlsKt.getPl2()[i]); + tempList.add(videoEntity); + } + //随机打乱 + Collections.shuffle(tempList); + videos.addAll(tempList); + } + + private void loadData() { + //模拟网络加载 + refreshLayout.finishRefresh(1500); + videos.clear(); + addData(); + adapterVideoList.notifyDataSetChanged(); + } + + /** + * 重复添加数据,模拟加载更多 + */ + private void loadMore() { + refreshLayout.finishLoadMore(1500); + addData(); + adapterVideoList.notifyDataSetChanged(); } @Override diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/adapter/CommentAdapter.java b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/adapter/CommentAdapter.java index 2289f040..e0e437a4 100644 --- a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/adapter/CommentAdapter.java +++ b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/adapter/CommentAdapter.java @@ -11,8 +11,9 @@ import com.bumptech.glide.Glide; +import org.jzvd.jzvideo.UrlsKt; + import cn.jzvd.demo.R; -import cn.jzvd.demo.Urls; public class CommentAdapter extends RecyclerView.Adapter { @@ -27,10 +28,13 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { @Override public void onBindViewHolder(ViewHolder holder, int position) { - Glide.with(holder.ivHead.getContext()).load(Urls.videoPosters[0][position]) + Glide.with(holder.ivHead.getContext()).load( + UrlsKt.getPl1()[position]) .into(holder.ivHead); - holder.tvName.setText(Urls.videoTitles[0][position]); - holder.tvContent.setText(Urls.videoTitles[0][position]); + holder.tvName.setText( + UrlsKt.getTl1()[position]); + holder.tvContent.setText( + UrlsKt.getVl1()[position]); } @Override diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/adapter/RecyclerViewAdapter.java b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/adapter/RecyclerViewAdapter.java index 4fbeddaa..c8ee7c6e 100644 --- a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/adapter/RecyclerViewAdapter.java +++ b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/adapter/RecyclerViewAdapter.java @@ -11,15 +11,16 @@ import com.bumptech.glide.Glide; +import org.jzvd.jzvideo.UrlsKt; + import cn.jzvd.Jzvd; import cn.jzvd.JzvdStd; import cn.jzvd.demo.R; -import cn.jzvd.demo.Urls; public class RecyclerViewAdapter extends RecyclerView.Adapter { public static final String TAG = "AdapterRecyclerView"; - int[] videoIndexs = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + int[] videoIndexs = {0, 1, 2, 3, 4, 5, 6, 7, 8}; private Context context; public RecyclerViewAdapter(Context context) { @@ -40,9 +41,12 @@ public void onBindViewHolder(MyViewHolder holder, int position) { Log.i(TAG, "onBindViewHolder [" + holder.jzvdStd.hashCode() + "] position=" + position); holder.jzvdStd.setUp( - Urls.videoUrls[0][position], - Urls.videoTitles[0][position], Jzvd.SCREEN_NORMAL); - Glide.with(holder.jzvdStd.getContext()).load(Urls.videoPosters[0][position]).into(holder.jzvdStd.posterImageView); + + UrlsKt.getVl1()[position], + + UrlsKt.getTl1()[position], Jzvd.SCREEN_NORMAL); + Glide.with(holder.jzvdStd.getContext()).load( + UrlsKt.getPl1()[position]).into(holder.jzvdStd.posterImageView); } @Override diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/adapter/RecyclerViewLoadMoreAdapter.java b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/adapter/RecyclerViewLoadMoreAdapter.java new file mode 100644 index 00000000..0a4f23c9 --- /dev/null +++ b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/adapter/RecyclerViewLoadMoreAdapter.java @@ -0,0 +1,63 @@ +package cn.jzvd.demo.Tab_3_List.ListView.adapter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.recyclerview.widget.RecyclerView; + +import com.bumptech.glide.Glide; + +import java.util.ArrayList; + +import cn.jzvd.Jzvd; +import cn.jzvd.JzvdStd; +import cn.jzvd.demo.R; +import cn.jzvd.demo.utils.VideoEntity; + +public class RecyclerViewLoadMoreAdapter extends RecyclerView.Adapter { + + public static final String TAG = "RecyclerViewLoadMoreAdapter"; + ArrayList videos; + private Context context; + + public RecyclerViewLoadMoreAdapter(Context context, ArrayList videos) { + this.context = context; + this.videos = videos; + } + + @Override + public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + MyViewHolder holder = new MyViewHolder(LayoutInflater.from( + context).inflate(R.layout.item_videoview, parent, + false)); + return holder; + } + + @SuppressLint("LongLogTag") + @Override + public void onBindViewHolder(MyViewHolder holder, int position) { + Log.i(TAG, "onBindViewHolder [" + holder.jzvdStd.hashCode() + "] position=" + position); + VideoEntity videoEntity = videos.get(position); + holder.jzvdStd.setUp(videoEntity.getUrl(), videoEntity.getTitle(), Jzvd.SCREEN_NORMAL); + Glide.with(holder.jzvdStd.getContext()).load(videoEntity.getThumb()).into(holder.jzvdStd.posterImageView); + } + + @Override + public int getItemCount() { + return videos.size(); + } + + class MyViewHolder extends RecyclerView.ViewHolder { + JzvdStd jzvdStd; + + public MyViewHolder(View itemView) { + super(itemView); + jzvdStd = itemView.findViewById(R.id.videoplayer); + } + } + +} diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/adapter/RecyclerViewTinyAdapter.java b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/adapter/RecyclerViewTinyAdapter.java index 01a9be41..1981ee6d 100644 --- a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/adapter/RecyclerViewTinyAdapter.java +++ b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/adapter/RecyclerViewTinyAdapter.java @@ -11,10 +11,11 @@ import com.bumptech.glide.Glide; +import org.jzvd.jzvideo.UrlsKt; + import cn.jzvd.Jzvd; import cn.jzvd.demo.CustomJzvd.JzvdStdTinyWindow; import cn.jzvd.demo.R; -import cn.jzvd.demo.Urls; public class RecyclerViewTinyAdapter extends RecyclerView.Adapter { @@ -41,9 +42,9 @@ public void onBindViewHolder(MyViewHolder holder, int position) { if (holder.jzvdStd.getTag() != null) holder.jzvdStd = ((View) holder.jzvdStd.getTag()).findViewById(R.id.videoplayer); holder.jzvdStd.setUp( - Urls.videoUrls[0][position], - Urls.videoTitles[0][position], Jzvd.SCREEN_NORMAL); - Glide.with(holder.jzvdStd.getContext()).load(Urls.videoPosters[0][position]).into(holder.jzvdStd.posterImageView); + UrlsKt.getVl1()[position], + UrlsKt.getVl1()[position], Jzvd.SCREEN_NORMAL); + Glide.with(holder.jzvdStd.getContext()).load(UrlsKt.getVl1()[position]).into(holder.jzvdStd.posterImageView); } @Override diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/adapter/SmoothRecyclerViewAdapter.java b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/adapter/SmoothRecyclerViewAdapter.java index f4184b73..066cf473 100644 --- a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/adapter/SmoothRecyclerViewAdapter.java +++ b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/adapter/SmoothRecyclerViewAdapter.java @@ -11,10 +11,11 @@ import com.bumptech.glide.Glide; +import org.jzvd.jzvideo.UrlsKt; + import cn.jzvd.Jzvd; import cn.jzvd.demo.CustomJzvd.JzvdStdRv; import cn.jzvd.demo.R; -import cn.jzvd.demo.Urls; import cn.jzvd.demo.utils.AutoPlayUtils; import cn.jzvd.demo.utils.ViewAttr; @@ -64,9 +65,10 @@ public void onBindViewHolder(MyViewHolder holder, int position) { jzvdStdRv = (JzvdStdRv) holder.container.getChildAt(0); } jzvdStdRv.setUp( - Urls.videoUrls[0][position], - Urls.videoTitles[0][position], Jzvd.SCREEN_NORMAL); - Glide.with(holder.container.getContext()).load(Urls.videoPosters[0][position]) + UrlsKt.getVl1()[position], + UrlsKt.getTl1()[position], Jzvd.SCREEN_NORMAL); + Glide.with(holder.container.getContext()).load( + UrlsKt.getPl1()[position]) .into(jzvdStdRv.posterImageView); } jzvdStdRv.setId(R.id.jzvdplayer); diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/tiktok/TikTokRecyclerViewAdapter.java b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/tiktok/TikTokRecyclerViewAdapter.java index e6c245c9..836ffe1e 100644 --- a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/tiktok/TikTokRecyclerViewAdapter.java +++ b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/ListView/tiktok/TikTokRecyclerViewAdapter.java @@ -11,16 +11,17 @@ import com.bumptech.glide.Glide; +import org.jzvd.jzvideo.UrlsKt; + import cn.jzvd.JZDataSource; import cn.jzvd.Jzvd; import cn.jzvd.demo.CustomJzvd.JzvdStdTikTok; import cn.jzvd.demo.R; -import cn.jzvd.demo.Urls; public class TikTokRecyclerViewAdapter extends RecyclerView.Adapter { public static final String TAG = "AdapterTikTokRecyclerView"; - int[] videoIndexs = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + int[] videoIndexs = {0, 1, 2, 3, 4, 5}; private Context context; public TikTokRecyclerViewAdapter(Context context) { @@ -40,11 +41,11 @@ public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { public void onBindViewHolder(MyViewHolder holder, int position) { Log.i(TAG, "onBindViewHolder [" + holder.jzvdStd.hashCode() + "] position=" + position); - JZDataSource jzDataSource = new JZDataSource(Urls.videoUrls[3][position], - Urls.videoTitles[0][position]); + JZDataSource jzDataSource = new JZDataSource(UrlsKt.getVl3()[position], + UrlsKt.getTl3()[position]); jzDataSource.looping = true; holder.jzvdStd.setUp(jzDataSource, Jzvd.SCREEN_NORMAL); - Glide.with(holder.jzvdStd.getContext()).load(Urls.videoPosters[0][position]).into(holder.jzvdStd.posterImageView); + Glide.with(holder.jzvdStd.getContext()).load(UrlsKt.getPl3()[position]).into(holder.jzvdStd.posterImageView); } @Override diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/TinyWindow/TinyWindowActivity.java b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/TinyWindow/TinyWindowActivity.java index d1a132aa..197b1914 100644 --- a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/TinyWindow/TinyWindowActivity.java +++ b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/TinyWindow/TinyWindowActivity.java @@ -10,6 +10,8 @@ import com.bumptech.glide.Glide; +import org.jzvd.jzvideo.UrlsKt; + import cn.jzvd.Jzvd; import cn.jzvd.JzvdStd; import cn.jzvd.demo.CustomJzvd.JzvdStdTinyWindow; @@ -34,10 +36,11 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { setContentView(R.layout.activity_tiny_window); jzvdStdTinyWindow = findViewById(R.id.jz_video); - jzvdStdTinyWindow.setUp("http://jzvd.nathen.cn/342a5f7ef6124a4a8faf00e738b8bee4/cf6d9db0bd4d41f59d09ea0a81e918fd-5287d2089db37e62345123a1be272f8b.mp4", "饺子快长大" + jzvdStdTinyWindow.setUp(UrlsKt.getVideos()[9], + UrlsKt.getTitles()[9] , JzvdStd.SCREEN_NORMAL); Glide.with(this) - .load("http://jzvd-pic.nathen.cn/jzvd-pic/1bb2ebbe-140d-4e2e-abd2-9e7e564f71ac.png") + .load(UrlsKt.getThumbnails()[9]) .into(jzvdStdTinyWindow.posterImageView); } diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/TinyWindow/TinyWindowRecycleViewMultiHolderActivity.java b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/TinyWindow/TinyWindowRecycleViewMultiHolderActivity.java index e2882091..43fd7a69 100644 --- a/demo/src/main/java/cn/jzvd/demo/Tab_3_List/TinyWindow/TinyWindowRecycleViewMultiHolderActivity.java +++ b/demo/src/main/java/cn/jzvd/demo/Tab_3_List/TinyWindow/TinyWindowRecycleViewMultiHolderActivity.java @@ -15,11 +15,12 @@ import com.bumptech.glide.Glide; +import org.jzvd.jzvideo.UrlsKt; + import cn.jzvd.Jzvd; import cn.jzvd.JzvdStd; import cn.jzvd.demo.CustomJzvd.JzvdStdTinyWindow; import cn.jzvd.demo.R; -import cn.jzvd.demo.Urls; /** * Created by Nathen on 2017/11/1. @@ -132,11 +133,9 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { TextHolder textHolder = (TextHolder) holder; } else { VideoHolder videoHolder = (VideoHolder) holder; - videoHolder.jzvdStd.setUp( - Urls.videoUrls[0][position], - Urls.videoTitles[0][position], Jzvd.SCREEN_NORMAL); + videoHolder.jzvdStd.setUp(UrlsKt.getVl1()[position], UrlsKt.getTl1()[position], Jzvd.SCREEN_NORMAL); videoHolder.jzvdStd.positionInList = position; - Glide.with(TinyWindowRecycleViewMultiHolderActivity.this).load(Urls.videoPosters[0][position]).into(videoHolder.jzvdStd.posterImageView); + Glide.with(TinyWindowRecycleViewMultiHolderActivity.this).load(UrlsKt.getPl1()[position]).into(videoHolder.jzvdStd.posterImageView); } } diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_4_More/DanmuActivity.java b/demo/src/main/java/cn/jzvd/demo/Tab_4_More/DanmuActivity.java new file mode 100644 index 00000000..a3ea025f --- /dev/null +++ b/demo/src/main/java/cn/jzvd/demo/Tab_4_More/DanmuActivity.java @@ -0,0 +1,121 @@ +package cn.jzvd.demo.Tab_4_More; + +import android.os.Bundle; +import android.os.Handler; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; + +import com.bumptech.glide.Glide; + +import org.jzvd.jzvideo.UrlsKt; + +import cn.jzvd.JZUtils; +import cn.jzvd.Jzvd; +import cn.jzvd.demo.CustomJzvd.JzvdDanmu; +import cn.jzvd.demo.R; + +/** + * @author Liberations + * @time 2020-12-01 + * @des 弹幕库 https://github.com/bilibili/DanmakuFlameMaster + */ +public class DanmuActivity extends AppCompatActivity implements View.OnClickListener { + private JzvdDanmu jzvdDanmu; + private Button btnDanmu, btnDiyDanmu,showDanmu,hideDanmu; + private Handler handler = new Handler(); + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + getSupportActionBar().setDisplayShowTitleEnabled(true); + getSupportActionBar().setDisplayUseLogoEnabled(false); + getSupportActionBar().setTitle(getString(R.string.danmu_show)); + setContentView(R.layout.activity_danmu); + btnDanmu = findViewById(R.id.btn_add_danmu); + btnDiyDanmu = findViewById(R.id.btn_diy_danmu); + showDanmu = findViewById(R.id.show_danmu); + hideDanmu = findViewById(R.id.hide_danmu); + jzvdDanmu = findViewById(R.id.jz_danmu_player); + btnDanmu.setOnClickListener(this); + btnDiyDanmu.setOnClickListener(this); + showDanmu.setOnClickListener(this); + hideDanmu.setOnClickListener(this); + + + jzvdDanmu.setUp(UrlsKt.getVideos()[14], UrlsKt.getTitles()[14], Jzvd.SCREEN_NORMAL); + Glide.with(this).load(UrlsKt.getThumbnails()[14]).into(jzvdDanmu.posterImageView); + testDanmu(); + jzvdDanmu.startButton.performClick(); + + } + + /** + * 模拟弹幕 + */ + private void testDanmu() { + handler.removeCallbacksAndMessages(null); + handler.post(new Runnable() { + @Override + public void run() { + jzvdDanmu.addDanmaku("嫂子666", false); + handler.postDelayed(this, 100); + } + }); + } + + @Override + protected void onPause() { + super.onPause(); + JZUtils.clearSavedProgress(this, null); + Jzvd.releaseAllVideos(); + } + + @Override + public void onBackPressed() { + if (Jzvd.backPress()) { + return; + } + super.onBackPressed(); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + finish(); + break; + } + return super.onOptionsItemSelected(item); + } + + @Override + public void onClick(View view) { + switch (view.getId()) { + case R.id.show_danmu: + jzvdDanmu.showDanmmu(); + break; + case R.id.hide_danmu: + jzvdDanmu.hideDanmmu(); + break; + case R.id.btn_add_danmu: + jzvdDanmu.addDanmaku("骚还是各位骚呀", true); + break; + case R.id.btn_diy_danmu: + jzvdDanmu.addDanmakuWithDrawable(); + break; + } + } + + @Override + protected void onDestroy() { + super.onDestroy(); + handler.removeCallbacksAndMessages(null); + jzvdDanmu.releaseDanMu(); + } +} diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_4_More/DirectPlayActivity.java b/demo/src/main/java/cn/jzvd/demo/Tab_4_More/DirectPlayActivity.java index 2ebb9140..f0bbdb77 100644 --- a/demo/src/main/java/cn/jzvd/demo/Tab_4_More/DirectPlayActivity.java +++ b/demo/src/main/java/cn/jzvd/demo/Tab_4_More/DirectPlayActivity.java @@ -8,10 +8,11 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import org.jzvd.jzvideo.UrlsKt; + import cn.jzvd.Jzvd; import cn.jzvd.JzvdStd; import cn.jzvd.demo.R; -import cn.jzvd.demo.Urls; /** * Created by Nathen on 16/7/31. @@ -54,7 +55,7 @@ public boolean onOptionsItemSelected(MenuItem item) { } public void clickFullScreen(View view) { - JzvdStd.startFullscreenDirectly(this, JzvdStd.class, Urls.videoUrlList[6], "饺子辛苦了"); + JzvdStd.startFullscreenDirectly(this, JzvdStd.class, UrlsKt.getVideos()[15], UrlsKt.getTitles()[15]); } public void clickTinyWindow(View view) { diff --git a/demo/src/main/java/cn/jzvd/demo/Tab_4_More/WebViewActivity.java b/demo/src/main/java/cn/jzvd/demo/Tab_4_More/WebViewActivity.java index 30fb298d..50100d1d 100644 --- a/demo/src/main/java/cn/jzvd/demo/Tab_4_More/WebViewActivity.java +++ b/demo/src/main/java/cn/jzvd/demo/Tab_4_More/WebViewActivity.java @@ -13,11 +13,12 @@ import com.bumptech.glide.Glide; +import org.jzvd.jzvideo.UrlsKt; + import cn.jzvd.JZUtils; import cn.jzvd.Jzvd; import cn.jzvd.JzvdStd; import cn.jzvd.demo.R; -import cn.jzvd.demo.Urls; /** * Created by Nathen on 16/10/13. @@ -73,11 +74,9 @@ public void adViewJiaoZiVideoPlayer(final int width, final int height, final int runOnUiThread(() -> { if (index == 0) { JzvdStd jzvdStd = new JzvdStd(WebViewActivity.this); - jzvdStd.setUp(Urls.videoUrlList[1], "饺子骑大马", - Jzvd.SCREEN_NORMAL); - Glide.with(WebViewActivity.this) - .load(Urls.videoPosterList[1]) - .into(jzvdStd.posterImageView); + jzvdStd.setUp(UrlsKt.getVideos()[16], UrlsKt.getTitles()[16], Jzvd.SCREEN_NORMAL); + Glide.with(WebViewActivity.this).load(UrlsKt.getThumbnails()[16]).into(jzvdStd.posterImageView); + ViewGroup.LayoutParams ll = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); AbsoluteLayout.LayoutParams layoutParams = new AbsoluteLayout.LayoutParams(ll); layoutParams.y = JZUtils.dip2px(WebViewActivity.this, top); @@ -90,11 +89,9 @@ public void adViewJiaoZiVideoPlayer(final int width, final int height, final int mWebView.addView(linearLayout, layoutParams); } else { JzvdStd jzvdStd = new JzvdStd(WebViewActivity.this); - jzvdStd.setUp(Urls.videoUrlList[2], "饺子失态了", - Jzvd.SCREEN_NORMAL); - Glide.with(WebViewActivity.this) - .load(Urls.videoPosterList[2]) - .into(jzvdStd.posterImageView); + jzvdStd.setUp(UrlsKt.getVideos()[16], UrlsKt.getTitles()[16], Jzvd.SCREEN_NORMAL); + Glide.with(WebViewActivity.this).load(UrlsKt.getThumbnails()[16]).into(jzvdStd.posterImageView); + ViewGroup.LayoutParams ll = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); AbsoluteLayout.LayoutParams layoutParams = new AbsoluteLayout.LayoutParams(ll); layoutParams.y = JZUtils.dip2px(WebViewActivity.this, top); diff --git a/demo/src/main/java/cn/jzvd/demo/Urls.java b/demo/src/main/java/cn/jzvd/demo/Urls.java deleted file mode 100644 index 275d84ae..00000000 --- a/demo/src/main/java/cn/jzvd/demo/Urls.java +++ /dev/null @@ -1,274 +0,0 @@ -package cn.jzvd.demo; - -/** - * Created by shengjun on 16/9/10. - */ -public class Urls { - - public static String[] videoUrlList = - { - "http://jzvd.nathen.cn/c494b340ff704015bb6682ffde3cd302/64929c369124497593205a4190d7d128-5287d2089db37e62345123a1be272f8b.mp4", - "http://jzvd.nathen.cn/63f3f73712544394be981d9e4f56b612/69c5767bb9e54156b5b60a1b6edeb3b5-5287d2089db37e62345123a1be272f8b.mp4", - "http://jzvd.nathen.cn/b201be3093814908bf987320361c5a73/2f6d913ea25941ffa78cc53a59025383-5287d2089db37e62345123a1be272f8b.mp4", - "http://jzvd.nathen.cn/d2438fd1c37c4618a704513ad38d68c5/68626a9d53ca421c896ac8010f172b68-5287d2089db37e62345123a1be272f8b.mp4", - "http://jzvd.nathen.cn/25a8d119cfa94b49a7a4117257d8ebd7/f733e65a22394abeab963908f3c336db-5287d2089db37e62345123a1be272f8b.mp4", - "http://jzvd.nathen.cn/7512edd1ad834d40bb5b978402274b1a/9691c7f2d7b74b5e811965350a0e5772-5287d2089db37e62345123a1be272f8b.mp4", - "http://jzvd.nathen.cn/c6e3dc12a1154626b3476d9bf3bd7266/6b56c5f0dc31428083757a45764763b0-5287d2089db37e62345123a1be272f8b.mp4" - }; - - public static String[] clarities = { - "https://jzvd.nathen.cn/video/460bad24-170c5bc6956-0007-1823-c86-de200.mp4", - "https://jzvd.nathen.cn/video/2b64c629-17204eaa4fa-0007-1823-c86-de200.mp4", - "https://jzvd.nathen.cn/video/a70a7fb-17204eaa501-0007-1823-c86-de200.mp4" - }; - - public static String[] videoPosterList = - { - "http://jzvd-pic.nathen.cn/jzvd-pic/00b026e7-b830-4994-bc87-38f4033806a6.jpg", - "http://jzvd-pic.nathen.cn/jzvd-pic/1d935cc5-a1e7-4779-bdfa-20fd7a60724c.jpg", - "http://jzvd-pic.nathen.cn/jzvd-pic/a019ffc1-556c-4a85-b70c-b1b49811d577.jpg", - "http://jzvd-pic.nathen.cn/jzvd-pic/6fc2ae91-36e2-44c5-bb10-29ae5d5c678c.png", - "http://jzvd-pic.nathen.cn/jzvd-pic/f03cee95-9b78-4dd5-986f-d162c06c385c.png", - "http://jzvd-pic.nathen.cn/jzvd-pic/e7ea659f-c3d2-4979-9ea5-f993b05e5930.png", - "" - }; - - public static String[][] videoUrls = - { - { - "http://jzvd.nathen.cn/6ea7357bc3fa4658b29b7933ba575008/fbbba953374248eb913cb1408dc61d85-5287d2089db37e62345123a1be272f8b.mp4", - "http://jzvd.nathen.cn/35b3dc97fbc240219961bd1fccc6400b/8d9b76ab5a584bce84a8afce012b72d3-5287d2089db37e62345123a1be272f8b.mp4", - "http://jzvd.nathen.cn/df6096e7878541cbbea3f7298683fbed/ef76450342914427beafe9368a4e0397-5287d2089db37e62345123a1be272f8b.mp4", - "http://jzvd.nathen.cn/384d341e000145fb82295bdc54ecef88/103eab5afca34baebc970378dd484942-5287d2089db37e62345123a1be272f8b.mp4", - "http://jzvd.nathen.cn/f55530ba8a59403da0621cbf4faef15e/adae4f2e3ecf4ea780beb057e7bce84c-5287d2089db37e62345123a1be272f8b.mp4", - "http://jzvd.nathen.cn/6340efd1962946ad80eeffd19b3be89c/65b499c0f16e4dd8900497e51ffa0949-5287d2089db37e62345123a1be272f8b.mp4", - "http://jzvd.nathen.cn/f07fa9fddd1e45a6ae1570c7fe7967c1/c6db82685b894e25b523b1cb28d79f2e-5287d2089db37e62345123a1be272f8b.mp4", - "http://jzvd.nathen.cn/d2e969f2ec734520b46ab0965d2b68bd/f124edfef6c24be8b1a7b7f996ccc5e0-5287d2089db37e62345123a1be272f8b.mp4", - "http://jzvd.nathen.cn/4f965ad507ef4194a60a943a34cfe147/32af151ea132471f92c9ced2cff785ea-5287d2089db37e62345123a1be272f8b.mp4", - "http://jzvd.nathen.cn/342a5f7ef6124a4a8faf00e738b8bee4/cf6d9db0bd4d41f59d09ea0a81e918fd-5287d2089db37e62345123a1be272f8b.mp4" - }, - { - "http://jzvd.nathen.cn/623f75c3beea4b1781ea37940e70bbe4/b9cee3fd1a09487ca99ef789cdc41312-5287d2089db37e62345123a1be272f8b.mp4", - "http://jzvd.nathen.cn/d8c137ceba9849f8b2f454a55a96266f/910c8381ff894905b5bc272f8194382a-5287d2089db37e62345123a1be272f8b.mp4", - "http://jzvd.nathen.cn/b8a589e5f12c45fdad96674d08affd31/f1d7229f553f414283033af3e292c6c9-5287d2089db37e62345123a1be272f8b.mp4", - "http://jzvd.nathen.cn/8abcdf98ec6a418b945a70fe9dd6fc7f/5cb36416a23a4da8b15d3eaa5e19a1e6-5287d2089db37e62345123a1be272f8b.mp4" - }, - { - "http://jzvd.nathen.cn/1b61da23555d4ce28c805ea303711aa5/7a33ac2af276441bb4b9838f32d8d710-5287d2089db37e62345123a1be272f8b.mp4", - "http://jzvd.nathen.cn/d525f756aabf4b0588c2152fb94e07f5/d9f59bef829a472a9ca066620d9b871a-5287d2089db37e62345123a1be272f8b.mp4", - "http://jzvd.nathen.cn/6e2fdec45dfa44a6802e95f8e4bc3280/a6a5273ac4244333923991be0583ffc7-5287d2089db37e62345123a1be272f8b.mp4", - "http://jzvd.nathen.cn/22b4de0e2b1245959c5baa77fe0bf14e/896a137559084b7eb879f5441faff20d-5287d2089db37e62345123a1be272f8b.mp4" - }, - {//tiktok - "http://jzvd.nathen.cn/video/1137e480-170bac9c523-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/e0bd348-170bac9c3b8-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/7bf938c-170bac9c18a-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/2f03c005-170bac9abac-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/47788f38-170bac9ab8a-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/2d6ffe8f-170bac9ab87-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/633e0ce-170bac9ab65-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/2d6ffe8f-170bac9ab87-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/51f7552c-170bac98718-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/2a101070-170bad88892-0007-1823-c86-de200.mp4" - } - }; - - public static String[] ssVideos = { - //0 - "http://jzvd.nathen.cn/video/4542c17b-170c25a8e14-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/5ab693c5-170c25a8e2b-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/375dd5c6-170c25a8e44-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/51e8b629-170c25a8e61-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/1fbd7323-170c25a8e7c-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/3697e6a5-170c5a17543-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/3697e6a5-170c5a17543-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/23755490-170c5a23aa2-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/3485af57-170c5a23b57-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/4c40d283-170c5a23bbe-0007-1823-c86-de200.mp4", -//1 - "http://jzvd.nathen.cn/video/33a3d257-170c5a23c2b-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/2aa00271-170c0924702-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/544973c7-170c092471a-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/4da19896-170c092473b-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/3e6b7f3a-170c0924763-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/8c1d8d9-170c0924776-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/3ed29468-170c099b43f-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/3f52bb8f-170c099f9ab-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/1248915c-170c09a1ce6-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/1c6529ed-170c09a2468-0007-1823-c86-de200.mp4", -//2 - "http://jzvd.nathen.cn/video/53e65db2-170c09a6c1d-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/11131240-170c5b076c4-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/5d6f2372-170c09b3ae0-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/5cc9b365-170c5b076d8-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/13ef1d98-170c09b3b9a-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/2f795df7-170c09b3bed-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/4b76aaac-170c09b3c8f-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/3bad72f7-170c09dc89f-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/581fbe-170c09dee3f-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/2aed5c6f-170c09dfbc3-0007-1823-c86-de200.mp4", -//3 - "http://jzvd.nathen.cn/video/3c0038bd-170c0a06ca0-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/15cace49-170c0a075f7-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/ed1d3ef-170c0a078cd-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/1fe7adc2-170c0afd71a-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/2c1d36cc-170c0afd12c-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/2083feba-170c0afd719-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/39105916-170c0afd718-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/2bc8f057-170c0afd716-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/2b8e9a15-170c0afd71c-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/43a91267-170c0afd719-0007-1823-c86-de200.mp4", -//4 - "http://jzvd.nathen.cn/video/33d5835a-170c0afd717-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/259ea2dd-170c0b41b5d-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/4e82a1ea-170c5bc6941-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/460bad24-170c5bc6956-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/5a2bc514-170c261eff0-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/11b3c81-170c261eff3-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/47d75a32-170c0b41c2b-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/10a5d0f8-170c261f25b-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/52cb5649-170c261f720-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/31f18965-170c2621a73-0007-1823-c86-de200.mp4", -//5 - "http://jzvd.nathen.cn/video/4a7b4838-170c267601a-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/554fe55-170c26772b4-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/31dbfe8e-170c2677478-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/30ab99b5-170c2677ca8-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/3acdb082-170c26793c3-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/4bf014a5-170c26aed4b-0007-1823-c86-de200.mp4", - "http://jzvd.nathen.cn/video/2f74432d-170c26afad2-0007-1823-c86-de200.mp4" - }; - public static String[] ssPoster = { - "http://jzvd.nathen.cn/snapshot/f402a0e012b14d41ad07939746844c5e00005.jpg", - "http://jzvd.nathen.cn/snapshot/4105cf36b9b8463ea9151c6ad73717d900005.jpg", - "http://jzvd.nathen.cn/snapshot/1ae064966b8b423887af71c3eba3bca100005.jpg", - "http://jzvd.nathen.cn/snapshot/4061ba7b7005452e81b643580eb4d30200005.jpg", - "http://jzvd.nathen.cn/snapshot/d7505ea52bca48828807bcf96161a9f500005.jpg", - "http://jzvd.nathen.cn/snapshot/9787cbe40b7848e9b82d2cc12d1c943500005.jpg", - "http://jzvd.nathen.cn/snapshot/9787cbe40b7848e9b82d2cc12d1c943500005.jpg", - "http://jzvd.nathen.cn/snapshot/1a78739a54de4575b7cec1d77a8df4a000005.jpg", - "http://jzvd.nathen.cn/snapshot/ef29b1922ea64780a8e77a5676cad95700005.jpg", - "http://jzvd.nathen.cn/snapshot/dabe6ca3c71942fd926a86c8996d750f00005.jpg", -//1 - "http://jzvd.nathen.cn/snapshot/14e8861d87c248ad83704dbe99b969f300005.jpg", - "http://jzvd.nathen.cn/snapshot/8bd6d06878fc4676a62290cbe8b5511f00005.jpg", - "http://jzvd.nathen.cn/snapshot/7254150df078451585464d804d42c71a00005.jpg", - "http://jzvd.nathen.cn/snapshot/c1ff75fcfd0042c4b7ecb762c13884eb00005.jpg", - "http://jzvd.nathen.cn/snapshot/4a5e4b468bce4179a9d97b4b40a80e0f00005.jpg", - "http://jzvd.nathen.cn/snapshot/bbe6f26a9af34ff4aa5d0e7919bd1e2f00005.jpg", - "http://jzvd.nathen.cn/snapshot/2a09ede3702c462db4f0fc8eb56821b700005.jpg", - "http://jzvd.nathen.cn/snapshot/ba84ad1beddf4d699596537b5bbbdd4900005.jpg", - "http://jzvd.nathen.cn/snapshot/9f9f5372013d4494a9fabb1c7df770ba00005.jpg", - "http://jzvd.nathen.cn/snapshot/732eb57fc0d447909eccc1adb60822c700005.jpg", -//2 - "http://jzvd.nathen.cn/snapshot/371ddcdf7bbe46b682913f3d3353192000005.jpg", - "http://jzvd.nathen.cn/snapshot/b0eae85eab344427b77a162a1f7c46ae00005.jpg", - "http://jzvd.nathen.cn/snapshot/99bac3c2114545cf81cf66646c1e93af00005.jpg", - "http://jzvd.nathen.cn/snapshot/b538b1feda4943ffbd84e84cab0a2fce00005.jpg", - "http://jzvd.nathen.cn/snapshot/001ffec854be4c70a2baf3e9219705b100005.jpg", - "http://jzvd.nathen.cn/snapshot/eed4cbff7dce42a9ae2a54606be2573e00005.jpg", - "http://jzvd.nathen.cn/snapshot/b9bf3204fd75493aacdb83ecb9cef71300005.jpg", - "http://jzvd.nathen.cn/snapshot/43b2946bc6f24451b7118dd3861378ab00005.jpg", - "http://jzvd.nathen.cn/snapshot/43b2946bc6f24451b7118dd3861378ab00005.jpg", - "http://jzvd.nathen.cn/snapshot/3fc3f273ea394ec7bb79b668360160f700005.jpg", - "http://jzvd.nathen.cn/snapshot/edac56544e2f43bb827bd0e819db381000005.jpg", -//3 - "http://jzvd.nathen.cn/snapshot/1d32b21e058b4959ba759e7385eb4c7000005.jpg", - "http://jzvd.nathen.cn/snapshot/6625cbf8306843dfb4fd636cf5b237a900005.jpg", - "http://jzvd.nathen.cn/snapshot/04cd0101be0c4b3f8f4f9b1f07b8a6bc00005.jpg", - "http://jzvd.nathen.cn/snapshot/531f1e488eb84b898ae9ca7f6ba758ed00005.jpg", - "http://jzvd.nathen.cn/snapshot/ca387d7d2ea8407aa371c3ce2d346a6d00005.jpg", - "http://jzvd.nathen.cn/snapshot/858001d1e47f416b996eb04b60a4579700005.jpg", - "http://jzvd.nathen.cn/snapshot/397923c6af5a48fd981ee23fafe7095800005.jpg", - "http://jzvd.nathen.cn/snapshot/454c647c597340dc93a361f5bebfad4800005.jpg", - "http://jzvd.nathen.cn/snapshot/b3c23f24c04640aaa5a15b0ad6477e4700005.jpg", - "http://jzvd.nathen.cn/snapshot/7aafec2b6ce74b658cc6ea4268c492c500005.jpg", -//4 - "http://jzvd.nathen.cn/snapshot/48d7a9f34254467bb6a1bdc830a2469300005.jpg", - "http://jzvd.nathen.cn/snapshot/5ecbb98fda1347cd921c0534bbf5d0d300005.jpg", - "http://jzvd.nathen.cn/snapshot/c6bf92f63bea42d687b3a61d2c880d3200005.jpg", - "http://jzvd.nathen.cn/snapshot/ad0331e78393457d88ded2257d9e47c800005.jpg", - "http://jzvd.nathen.cn/snapshot/1f8acb2de146490e867b35f381f26f2900005.jpg", - "http://jzvd.nathen.cn/snapshot/0da5ed87cc1f4f4f9742b6fde232128d00005.jpg", - "http://jzvd.nathen.cn/snapshot/2cf5412fe161439a835371ce0b42f64f00005.jpg", - "http://jzvd.nathen.cn/snapshot/6ae53110f7fd470683587746f027698400005.jpg", - "http://jzvd.nathen.cn/snapshot/39cfa0b8eb0e4875ac0665448a09a9fa00005.jpg", - "http://jzvd.nathen.cn/snapshot/f7622efa12d74d1f955bf4d8d6e8c5a400005.jpg", -//5 - "http://jzvd.nathen.cn/snapshot/ef384b95897b470c80a4aca4dd1112a500005.jpg", - "http://jzvd.nathen.cn/snapshot/8715f1267152404199f900fc72c6521700005.jpg", - "http://jzvd.nathen.cn/snapshot/86a055d08b514c9ca1e76e76862105ec00005.jpg", - "http://jzvd.nathen.cn/snapshot/58c16ac1e01e4a12b7970ecc8d6e789100005.jpg", - "http://jzvd.nathen.cn/snapshot/abd73471be8745d5b90c8fec34f95a7600005.jpg", - "http://jzvd.nathen.cn/snapshot/c9a2dbd1b997417687312741d2efe62300005.jpg", - "http://jzvd.nathen.cn/snapshot/f92487e92d6a4d3faad2d60375416c5200005.jpg" - }; - - public static String[][] videoPosters = - { - { - "http://jzvd-pic.nathen.cn/jzvd-pic/bd7ffc84-8407-4037-a078-7d922ce0fb0f.jpg", - "http://jzvd-pic.nathen.cn/jzvd-pic/f2dbd12e-b1cb-4daf-aff1-8c6be2f64d1a.jpg", - "http://jzvd-pic.nathen.cn/jzvd-pic/ccd86ca1-66c7-4331-9450-a3b7f765424a.png", - "http://jzvd-pic.nathen.cn/jzvd-pic/2adde364-9be1-4864-b4b9-0b0bcc81ef2e.jpg", - "http://jzvd-pic.nathen.cn/jzvd-pic/2a877211-4b68-4e3a-87be-6d2730faef27.png", - "http://jzvd-pic.nathen.cn/jzvd-pic/aaeb5da9-ac50-4712-a28d-863fe40f1fc6.png", - "http://jzvd-pic.nathen.cn/jzvd-pic/e565f9cc-eedc-45f0-99f8-5b0fa3aed567%281%29.jpg", - "http://jzvd-pic.nathen.cn/jzvd-pic/3430ec64-e6a7-4d8e-b044-9d408e075b7c.jpg", - "http://jzvd-pic.nathen.cn/jzvd-pic/2204a578-609b-440e-8af7-a0ee17ff3aee.jpg", - "http://jzvd-pic.nathen.cn/jzvd-pic/1bb2ebbe-140d-4e2e-abd2-9e7e564f71ac.png" - }, - { - "http://jzvd-pic.nathen.cn/jzvd-pic/f18ee453-6aec-40a5-a046-3203111dd303.jpg", - "http://jzvd-pic.nathen.cn/jzvd-pic/00f5a243-1e9f-426c-94f4-888971987edb.jpg", - "http://jzvd-pic.nathen.cn/jzvd-pic/7df34ee9-1e4f-48f4-8acd-748c52368298.jpg", - "http://jzvd-pic.nathen.cn/jzvd-pic/ef46e139-e378-4298-8441-144888294f1f.png" - }, - { - "http://jzvd-pic.nathen.cn/jzvd-pic/0e58101d-5b47-4100-8fb3-0cce057fd622.jpg", - "http://jzvd-pic.nathen.cn/jzvd-pic/d6d3a520-b183-4867-8746-5b6aba6c1724.png", - "http://jzvd-pic.nathen.cn/jzvd-pic/caa3dade-5744-486d-a1b7-9780aebb9eb5.jpg", - "http://jzvd-pic.nathen.cn/jzvd-pic/2c3e62bb-6a32-4fb0-a1d5-d1260ad436a4.png" - }, - { - "http://jzvd.nathen.cn/snapshot/5f1bf07d953d4e50989e99cb45ba6b5d00002.jpg", - "http://jzvd.nathen.cn/snapshot/c0d873f60f664bf6a90c9a69bdf52be900002.jpg", - "http://jzvd.nathen.cn/snapshot/c8598fcf365542a28be332c19d666ec600002.jpg", - "http://jzvd.nathen.cn/snapshot/f2e9d9cb796f420faa0903a28800660e00001.jpg", - "http://jzvd.nathen.cn/snapshot/b3bb3dd69c804993bbd155225b873bdf00002.jpg", - "http://jzvd.nathen.cn/snapshot/43902ca792e84b1b8bee65e28a75177200001.jpg", - "http://jzvd.nathen.cn/snapshot/e027c24371d84a6296d824dc7a7d0aa600002.jpg", - "http://jzvd.nathen.cn/snapshot/c904a0e5627f4a48982c7d09c5dc79ec00001.jpg", - "http://jzvd.nathen.cn/snapshot/b6eacc0aae6049afbcf7cb9365c7694200002.jpg", - "http://jzvd.nathen.cn/snapshot/717f9195bac04ea589692a3143aa04b400002.jpg" - } - }; - - public static String[][] videoTitles = - { - { - "饺子出来", - "饺子溢出", - "饺子我姓王", - "饺子趴好了", - "饺子很渴", - "饺子这样不好", - "饺子别笑", - "饺子坐火车", - "饺子打游戏", - "饺子快长大" - }, - { - "饺子堵车了", - "饺子喝点", - "饺子快走", - "饺子别这样" - }, - { - "饺子想偷", - "饺子害羞了", - "饺子淡定", - "饺子好喜欢" - } - }; -} diff --git a/demo/src/main/java/cn/jzvd/demo/utils/CenteredImageSpan.java b/demo/src/main/java/cn/jzvd/demo/utils/CenteredImageSpan.java new file mode 100644 index 00000000..eb0f51ca --- /dev/null +++ b/demo/src/main/java/cn/jzvd/demo/utils/CenteredImageSpan.java @@ -0,0 +1,50 @@ +package cn.jzvd.demo.utils; + +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.Rect; +import android.graphics.drawable.Drawable; +import android.text.style.ImageSpan; + +/** + * 图文混排使图片文字基于中线对齐 + */ +public class CenteredImageSpan extends ImageSpan { + + public CenteredImageSpan(final Drawable drawable) { + super(drawable); + } + + @Override + public int getSize(Paint paint, CharSequence text, int start, int end, + Paint.FontMetricsInt fm) { + Drawable d = getDrawable(); + Rect rect = d.getBounds(); + if (fm != null) { + Paint.FontMetricsInt fmPaint = paint.getFontMetricsInt(); + int fontHeight = fmPaint.bottom - fmPaint.top; + int drHeight = rect.bottom - rect.top; + + int top = drHeight / 2 - fontHeight / 4; + int bottom = drHeight / 2 + fontHeight / 4; + + fm.ascent = -bottom; + fm.top = -bottom; + fm.bottom = top; + fm.descent = top; + } + return rect.right; + } + + @Override + public void draw(Canvas canvas, CharSequence text, int start, int end, + float x, int top, int y, int bottom, Paint paint) { + Drawable b = getDrawable(); + canvas.save(); + int transY; + transY = ((bottom - top) - b.getBounds().bottom) / 2 + top; + canvas.translate(x, transY); + b.draw(canvas); + canvas.restore(); + } +} diff --git a/demo/src/main/java/cn/jzvd/demo/utils/VideoEntity.java b/demo/src/main/java/cn/jzvd/demo/utils/VideoEntity.java new file mode 100644 index 00000000..1f45abd9 --- /dev/null +++ b/demo/src/main/java/cn/jzvd/demo/utils/VideoEntity.java @@ -0,0 +1,31 @@ +package cn.jzvd.demo.utils; + +public class VideoEntity { + private String url; + private String title; + private String thumb; + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getThumb() { + return thumb; + } + + public void setThumb(String thumb) { + this.thumb = thumb; + } +} diff --git a/demo/src/main/java/org/jzvd/jzvideo/urls.kt b/demo/src/main/java/org/jzvd/jzvideo/urls.kt new file mode 100644 index 00000000..8ddfd2b4 --- /dev/null +++ b/demo/src/main/java/org/jzvd/jzvideo/urls.kt @@ -0,0 +1,208 @@ +package org.jzvd.jzvideo + +// Chrome浏览器和饺子demo(android.MediaPlayer)相同时间相同网络环境播放,速度相差很远,为什么。 +// ijk好像略快,但没有电脑的chrome快。红米手机的自带浏览器可以完整观看视频无需中途加载。 + + +val cn = "http://8.136.101.204" +val us = "http://videos.jzvd.org" + +var server_name: String = cn + +val ldjVideos = arrayOf( + "$server_name/v/ldj/01-ldj.mp4", + "$server_name/v/ldj/02-ldj.mp4", + "$server_name/v/ldj/03-ldj.mp4", + "$server_name/v/ldj/04-ldj.mp4", + "$server_name/v/ldj/05-ldj.mp4", + "$server_name/v/ldj/06-ldj.mp4", + "$server_name/v/ldj/07-ldj.mp4", + "$server_name/v/ldj/08-ldj.mp4", + "$server_name/v/ldj/09-ldj.mp4", + "$server_name/v/ldj/10-ldj.mp4", + "$server_name/v/ldj/11-ldj.mp4", + "$server_name/v/ldj/12-ldj.mp4", + "$server_name/v/ldj/13-ldj.mp4", + "$server_name/v/ldj/14-ldj.mp4", + "$server_name/v/ldj/15-ldj.mp4", + "$server_name/v/ldj/16-ldj.mp4", + "$server_name/v/ldj/17-ldj.mp4", + "$server_name/v/ldj/18-ldj.mp4", + "$server_name/v/ldj/19-ldj.mp4", + "$server_name/v/ldj/20-ldj.mp4", + "$server_name/v/ldj/21-ldj.mp4", + "$server_name/v/ldj/22-ldj.mp4", + "$server_name/v/ldj/23-ldj.mp4", + "$server_name/v/ldj/24-ldj.mp4", + "$server_name/v/ldj/25-ldj.mp4", + "$server_name/v/ldj/26-ldj.mp4", + "$server_name/v/ldj/27-ldj.mp4", + "$server_name/v/ldj/28-ldj.mp4", + "$server_name/v/ldj/29-ldj.mp4", + "$server_name/v/ldj/30-ldj.mp4", + "$server_name/v/ldj/31-ldj.mp4", + "$server_name/v/ldj/32-ldj.mp4", + "$server_name/v/ldj/33-ldj.mp4", + "$server_name/v/ldj/34-ldj.mp4", + "$server_name/v/ldj/35-ldj.mp4", + "$server_name/v/ldj/36-ldj.mp4", + "$server_name/v/ldj/37-ldj.mp4", + "$server_name/v/ldj/38-ldj.mp4", + "$server_name/v/ldj/39-ldj.mp4", + "$server_name/v/ldj/40-ldj.mp4", + "$server_name/v/ldj/41-ldj.mp4", + "$server_name/v/ldj/42-ldj.mp4", + "$server_name/v/ldj/43-ldj.mp4", + "$server_name/v/ldj/44-ldj.mp4", + "$server_name/v/ldj/45-ldj.mp4" +) + +val cndVideos = arrayOf( + "https://jzvd.nathen.cn/video/cfe6c30-1767b1bc21f-0007-1823-c86-de200.mp4",//三个不同分辨率 + "https://jzvd.nathen.cn/0339d49439f947419576c33a0aa51545/79e1a938b0d2435d85bd964a77640506-f4e986e3e38ed3f473f7ba82bc07e188-ld.mp4", + "https://jzvd.nathen.cn/0339d49439f947419576c33a0aa51545/79e1a938b0d2435d85bd964a77640506-8924c7da92ebd789d315bc5de0a81059-fd.mp4", + + "https://jzvd.nathen.cn/video/59aa468b-1767b6d891e-0007-1823-c86-de200.mp4",//饺子还小 + "https://jzvd.nathen.cn/video/25ae1b1c-1767b2a5e44-0007-1823-c86-de200.mp4",//饺子还年轻 + "https://jzvd.nathen.cn/video/5a6465ff-1767b2a5e28-0007-1823-c86-de200.mp4" +) + +val cndThumbnail = arrayOf( + "https://jzvd.nathen.cn/snapshot/0339d49439f947419576c33a0aa5154500005.jpg", + "", + "", + + "https://jzvd.nathen.cn/snapshot/61c99f9225c04b24a1d0374e9a3f006700004.jpg", + "https://jzvd.nathen.cn/snapshot/044ef6cf452d48b795cea0a96ee4ea4100002.jpg", + "https://jzvd.nathen.cn/snapshot/a172cc6442ff40ffb826829fc78f83b700005.jpg" +) + +val videos = arrayOf( + //width > height + "$server_name/v/饺子主动.mp4", + "$server_name/v/饺子运动.mp4", + "$server_name/v/饺子有活.mp4", + "$server_name/v/饺子星光.mp4", + "$server_name/v/饺子想吹.mp4", + "$server_name/v/饺子汪汪.mp4", + "$server_name/v/饺子偷人.mp4", + "$server_name/v/饺子跳.mp4", + "$server_name/v/饺子受不了.mp4", + "$server_name/v/饺子三位.mp4", + "$server_name/v/饺子起飞.mp4", + "$server_name/v/饺子你听.mp4", + "$server_name/v/饺子可以了.mp4", + "$server_name/v/饺子还小.mp4", + "$server_name/v/饺子高兴.mp4", + "$server_name/v/饺子高冷.mp4", + "$server_name/v/饺子堵住了.mp4", + "$server_name/v/饺子都懂.mp4", + "$server_name/v/饺子打电话.mp4", + "$server_name/v/饺子不服.mp4", + //height > width + "$server_name/v/饺子还年轻.mp4", + "$server_name/v/饺子好妈妈.mp4", + "$server_name/v/饺子可以.mp4", + "$server_name/v/饺子挺住.mp4", + "$server_name/v/饺子想听.mp4", + "$server_name/v/饺子真会.mp4", + "$server_name/v/饺子真萌.mp4" + + ) + +val thumbnails = arrayOf( + "$server_name/v/饺子主动.jpg", + "$server_name/v/饺子运动.jpg", + "$server_name/v/饺子有活.jpg", + "$server_name/v/饺子星光.jpg", + "$server_name/v/饺子想吹.jpg", + "$server_name/v/饺子汪汪.jpg", + "$server_name/v/饺子偷人.jpg", + "$server_name/v/饺子跳.jpg", + "$server_name/v/饺子受不了.jpg", + "$server_name/v/饺子三位.jpg", + "$server_name/v/饺子起飞.jpg", + "$server_name/v/饺子你听.jpg", + "$server_name/v/饺子可以了.jpg", + "$server_name/v/饺子还小.jpg", + "$server_name/v/饺子高兴.jpg", + "$server_name/v/饺子高冷.jpg", + "$server_name/v/饺子堵住了.jpg", + "$server_name/v/饺子都懂.jpg", + "$server_name/v/饺子打电话.jpg", + "$server_name/v/饺子不服.jpg", + + //height > width + "$server_name/v/饺子还年轻.jpg", + "$server_name/v/饺子好妈妈.jpg", + "$server_name/v/饺子可以.jpg", + "$server_name/v/饺子挺住.jpg", + "$server_name/v/饺子想听.jpg", + "$server_name/v/饺子真会.jpg", + "$server_name/v/饺子真萌.jpg" + +) + +val titles = arrayOf( + //width > height + "饺子主动", + "饺子运动", + "饺子有活", + "饺子星光", + "饺子想吹", + "饺子汪汪", + "饺子偷人", + "饺子跳", + "饺子受不了", + "饺子三位", + + "饺子起飞", + "饺子你听", + "饺子可以了", + "饺子还小", + "饺子高兴", + "饺子高冷", + "饺子堵住了", + "饺子都懂", + "饺子打电话", + "饺子不服", + + //height > width + "饺子还年轻", + "饺子好妈妈", + "饺子可以", + "饺子挺住", + "饺子想听", + "饺子真会", + "饺子真萌" +) + +val vl1 = videos.copyOfRange(0, 9) +val pl1 = thumbnails.copyOfRange(0, 9) +val tl1 = titles.copyOfRange(0, 9) + +val vl2 = videos.copyOfRange(10, 20) +val pl2 = thumbnails.copyOfRange(10, 20) +val tl2 = titles.copyOfRange(10, 20) + +val vl3 = videos.copyOfRange(20, 26) +val pl3 = thumbnails.copyOfRange(20, 26) +val tl3 = titles.copyOfRange(20, 26) + + +val vll = arrayOf( + vl1, vl2, vl3 +) + +val pll = arrayOf( + pl1, pl2, pl3 +) + +val tll = arrayOf( + tl1, tl2, tl3 +) + + + + + diff --git a/demo/src/main/res/layout/activity_danmu.xml b/demo/src/main/res/layout/activity_danmu.xml new file mode 100644 index 00000000..c517f309 --- /dev/null +++ b/demo/src/main/res/layout/activity_danmu.xml @@ -0,0 +1,36 @@ + + + + +