|
@@ -1,8 +1,12 @@
|
|
|
package com.haochuan.hciptvbasic.webview;
|
|
|
|
|
|
+import android.animation.PropertyValuesHolder;
|
|
|
+import android.animation.ValueAnimator;
|
|
|
import android.app.Activity;
|
|
|
import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
import android.view.ViewGroup;
|
|
|
+import android.view.animation.LinearInterpolator;
|
|
|
import android.webkit.JavascriptInterface;
|
|
|
import android.webkit.WebView;
|
|
|
import android.widget.FrameLayout;
|
|
@@ -25,7 +29,6 @@ public class PlayerToJS {
|
|
|
String JS_EVENT_PLAYING = "javascript:onPlayerPlaying()";
|
|
|
String JS_EVENT_RESUME = "javascript:onPlayerResume()";
|
|
|
String JS_EVENT_PAUSE = "javascript:onPlayerPause()";
|
|
|
- String JS_EVENT_DESTROY="javascript:onPlayerDestroy()";
|
|
|
String JS_EVENT_PLAYINGBUFFER = "javascript:onPlayingBuffer()";
|
|
|
String JS_EVENT_COMPLETE = "javascript:onPlayerComplete()";
|
|
|
String JS_EVENT_PLAYERROR="javascript:onPlayerError(%s,%s)";
|
|
@@ -68,12 +71,7 @@ public class PlayerToJS {
|
|
|
JsUtil.evaluateJavascript(context,webView,JS_EVENT_PAUSE);
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
- * 播放器销毁释放事件
|
|
|
- * */
|
|
|
- public void onPlayerDestroy(){
|
|
|
- JsUtil.evaluateJavascript(context,webView,JS_EVENT_DESTROY);
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
/*
|
|
|
* 播放器缓冲事件
|
|
@@ -100,6 +98,11 @@ public class PlayerToJS {
|
|
|
|
|
|
/*
|
|
|
* 播放函数
|
|
|
+ * @param x 播放器x坐标
|
|
|
+ * @param y 播放器y坐标
|
|
|
+ * @param width 播放器宽度
|
|
|
+ * @param height 播放器高度
|
|
|
+ * @param seekTime 播放初始位置,单位 s
|
|
|
* */
|
|
|
@JavascriptInterface
|
|
|
public void play(String url,String seekTime, String x,String y,String width, String height){
|
|
@@ -107,6 +110,15 @@ public class PlayerToJS {
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
+ * 改变播放器尺寸
|
|
|
+ * */
|
|
|
+ @JavascriptInterface
|
|
|
+ public void change(String x,String y,String width, String height){
|
|
|
+ videoChange(x,y,width,height);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /*
|
|
|
* 暂停
|
|
|
* */
|
|
|
@JavascriptInterface
|
|
@@ -172,6 +184,11 @@ public class PlayerToJS {
|
|
|
|
|
|
/*
|
|
|
* 播放
|
|
|
+ * @param x 播放器x坐标
|
|
|
+ * @param y 播放器y坐标
|
|
|
+ * @param width 播放器宽度
|
|
|
+ * @param height 播放器高度
|
|
|
+ * @param seekTime 播放初始位置,单位 s
|
|
|
* */
|
|
|
private void videoPlay(String url,String seekTime, String x,String y,String width, String height){
|
|
|
if(baseMediaPlayer == null){
|
|
@@ -203,10 +220,10 @@ public class PlayerToJS {
|
|
|
baseMediaPlayer.setStartTime(realSeekTime);
|
|
|
webView.requestFocus();
|
|
|
});
|
|
|
+ }else{
|
|
|
+ Logger.w(String.format("请正确传递play函数参数:x:%s;y:%s;width:%s;height:%s;seekTime:%s",
|
|
|
+ x,y,width,height,seekTime));
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
@@ -237,6 +254,68 @@ public class PlayerToJS {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /*
|
|
|
+ * @param x 待改变播放器x坐标
|
|
|
+ * @param y 待改变播放器y坐标
|
|
|
+ * @param width 待改变播放器宽度
|
|
|
+ * @param height 待改变播放器高度
|
|
|
+ * */
|
|
|
+ private void videoChange(String x,String y,String width, String height){
|
|
|
+ if(baseMediaPlayer == null){
|
|
|
+ Logger.w("baseMediaPlayer is null,不能调用play函数");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(baseMediaPlayer.getParent() == null){
|
|
|
+ Logger.w("当前播放器没有启动,请先调用play函数启动");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(MathUtil.isDigitsOnly(x) && MathUtil.isDigitsOnly(y) && MathUtil.isDigitsOnly(width) && MathUtil.isDigitsOnly(height)){
|
|
|
+ int screenWidth = ScreenSnap.getScreenWidth(context);
|
|
|
+ int screenHeight = ScreenSnap.getScreenHeight(context);
|
|
|
+ int toX = (int) (Float.parseFloat(x) * screenWidth / 1280);
|
|
|
+ int toY = (int) (Float.parseFloat(y) * screenHeight / 720);
|
|
|
+ int toWidth = (int) (Float.parseFloat(width) * screenWidth / 1280);
|
|
|
+ int toHeight = (int) (Float.parseFloat(height) * screenHeight / 720);
|
|
|
+
|
|
|
+ int fromX = (int)baseMediaPlayer.getX();
|
|
|
+ int fromY = (int)baseMediaPlayer.getY();
|
|
|
+ int fromWidth = baseMediaPlayer.getWidth();
|
|
|
+ int fromHeight = baseMediaPlayer.getHeight();
|
|
|
+ animChanged(fromX,toX,fromY,toY,fromWidth,toWidth,fromHeight,toHeight);
|
|
|
+ }else{
|
|
|
+ Logger.w(String.format("请正确传递change函数参数:x:%s;y:%s;width:%s;height:%s",
|
|
|
+ x,y,width,height));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 以动画形式改变播放器尺寸
|
|
|
+ * */
|
|
|
+ private void animChanged(int fromX, int toX, int fromY, int toY, int fromWidth, int toWidth, int fromHeight, int toHeight) {
|
|
|
+ ValueAnimator animator = new ValueAnimator();
|
|
|
+ animator.setValues(
|
|
|
+ PropertyValuesHolder.ofFloat("x", fromX, toX),
|
|
|
+ PropertyValuesHolder.ofFloat("y", fromY, toY),
|
|
|
+ PropertyValuesHolder.ofInt("width", fromWidth, toWidth),
|
|
|
+ PropertyValuesHolder.ofInt("height", fromHeight, toHeight)
|
|
|
+ );
|
|
|
+ animator.setDuration(200);
|
|
|
+ animator.setInterpolator(new LinearInterpolator());
|
|
|
+ animator.addUpdateListener(valueAnimator -> {
|
|
|
+ FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
+ params.width = (int) valueAnimator.getAnimatedValue("width");
|
|
|
+ params.height = (int) valueAnimator.getAnimatedValue("height");
|
|
|
+
|
|
|
+ baseMediaPlayer.setLayoutParams(params);
|
|
|
+
|
|
|
+ baseMediaPlayer.setX((Float) valueAnimator.getAnimatedValue("x"));
|
|
|
+ baseMediaPlayer.setY((Float) valueAnimator.getAnimatedValue("y"));
|
|
|
+ });
|
|
|
+ animator.start();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private void destroyVideo(){
|
|
|
if(baseMediaPlayer != null && baseMediaPlayer.getParent() != null){
|