|
@@ -17,6 +17,11 @@ import android.view.animation.LinearInterpolator;
|
|
import android.widget.FrameLayout;
|
|
import android.widget.FrameLayout;
|
|
import android.widget.Toast;
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
+import com.android.volley.NetworkResponse;
|
|
|
|
+import com.android.volley.VolleyError;
|
|
|
|
+import com.android.volley.toolbox.HttpHeaderParser;
|
|
|
|
+import com.android.volley.toolbox.StringRequest;
|
|
|
|
+import com.android.volley.toolbox.Volley;
|
|
import com.hc.lib.http.GetRequest;
|
|
import com.hc.lib.http.GetRequest;
|
|
import com.hc.lib.http.GetRequestListener;
|
|
import com.hc.lib.http.GetRequestListener;
|
|
import com.hc.lib.video.MVideoPlayer;
|
|
import com.hc.lib.video.MVideoPlayer;
|
|
@@ -31,12 +36,17 @@ import com.orhanobut.logger.Logger;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONObject;
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
import java.util.Timer;
|
|
import java.util.Timer;
|
|
import java.util.TimerTask;
|
|
import java.util.TimerTask;
|
|
|
|
|
|
|
|
+
|
|
public class MainActivity extends BaseWebActivity implements AndroidToJS.PlayVideoListener {
|
|
public class MainActivity extends BaseWebActivity implements AndroidToJS.PlayVideoListener {
|
|
|
|
|
|
- final String url = com.hc.model.BuildConfig.Domain + com.hc.model.BuildConfig.port + "/h5v2/index.html";
|
|
|
|
|
|
+ final String url = com.hc.model.BuildConfig.Domain + com.hc.model.BuildConfig.port + "/h5v2/index.html";
|
|
|
|
+ //final String url = "http://112.35.32.145:8090/h5v2/template/haochuan.html"; //活动测试地址
|
|
|
|
+ //final String url ="http://112.35.32.145:8090/h5v2/subject/zt20190222/index.html";
|
|
|
|
+ //final String url = com.hc.model.BuildConfig.Domain + com.hc.model.BuildConfig.port + "/h5v2/template/haochuan.html";
|
|
//final String url ="http://112.35.32.145:8090/h5v2/sxyd_djbl.html?epgServer=http://111.20.42.147:33200&sourceId=1363&token=tgS09L3h7qp3w9-StjtSpqfq5";
|
|
//final String url ="http://112.35.32.145:8090/h5v2/sxyd_djbl.html?epgServer=http://111.20.42.147:33200&sourceId=1363&token=tgS09L3h7qp3w9-StjtSpqfq5";
|
|
|
|
|
|
// public static final String[] urls = {"http://9890.vod.myqcloud.com/9890_4e292f9a3dd011e6b4078980237cc3d3.f20.mp4",
|
|
// public static final String[] urls = {"http://9890.vod.myqcloud.com/9890_4e292f9a3dd011e6b4078980237cc3d3.f20.mp4",
|
|
@@ -56,7 +66,7 @@ public class MainActivity extends BaseWebActivity implements AndroidToJS.PlayVid
|
|
|
|
|
|
private VideoInfo lastVideoInfo;
|
|
private VideoInfo lastVideoInfo;
|
|
|
|
|
|
- private String TAG ="SXYD";
|
|
|
|
|
|
+ private String TAG ="MainActivity";
|
|
|
|
|
|
//add by 许林
|
|
//add by 许林
|
|
//float density = 0;
|
|
//float density = 0;
|
|
@@ -69,6 +79,9 @@ public class MainActivity extends BaseWebActivity implements AndroidToJS.PlayVid
|
|
|
|
|
|
// String myUid = "123456";
|
|
// String myUid = "123456";
|
|
|
|
|
|
|
|
+ //private VideoInfo currentFloatInfo;
|
|
|
|
+
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
super.onCreate(savedInstanceState);
|
|
@@ -78,6 +91,7 @@ public class MainActivity extends BaseWebActivity implements AndroidToJS.PlayVid
|
|
screenHeight = displayMetrics.heightPixels;
|
|
screenHeight = displayMetrics.heightPixels;
|
|
Log.d("MainActivity", "; width:" + screenWidth + "; height:" + screenHeight);
|
|
Log.d("MainActivity", "; width:" + screenWidth + "; height:" + screenHeight);
|
|
|
|
|
|
|
|
+
|
|
videoPlayer = new MVideoPlayer(MainActivity.this);
|
|
videoPlayer = new MVideoPlayer(MainActivity.this);
|
|
videoPlayer.setActivity(this);
|
|
videoPlayer.setActivity(this);
|
|
// 是否需要显示流量提示
|
|
// 是否需要显示流量提示
|
|
@@ -86,6 +100,9 @@ public class MainActivity extends BaseWebActivity implements AndroidToJS.PlayVid
|
|
controlDelegate = new VideoControlDelegate(this, videoPlayer);
|
|
controlDelegate = new VideoControlDelegate(this, videoPlayer);
|
|
controlDelegate.subscribeData();
|
|
controlDelegate.subscribeData();
|
|
controlDelegate.getExitPlayingEvent().observe(this, aBoolean -> {
|
|
controlDelegate.getExitPlayingEvent().observe(this, aBoolean -> {
|
|
|
|
+ //判断视频是否播放完成,来判断是否要储存上次播放时间
|
|
|
|
+ videoPlayer.storeLastPlayTime();
|
|
|
|
+
|
|
if (hadFloatVideo) {
|
|
if (hadFloatVideo) {
|
|
videoPlayer.hideAllWidget();
|
|
videoPlayer.hideAllWidget();
|
|
changeVideo2Float();
|
|
changeVideo2Float();
|
|
@@ -100,7 +117,6 @@ public class MainActivity extends BaseWebActivity implements AndroidToJS.PlayVid
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
-
|
|
|
|
videoPlayer.setOnPlayerPausedListener(controlDelegate);
|
|
videoPlayer.setOnPlayerPausedListener(controlDelegate);
|
|
|
|
|
|
//test
|
|
//test
|
|
@@ -110,6 +126,33 @@ public class MainActivity extends BaseWebActivity implements AndroidToJS.PlayVid
|
|
// videoPlayer.setLooping(false);
|
|
// videoPlayer.setLooping(false);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /* private void initMediaPlayer(){
|
|
|
|
+ videoPlayer = new MVideoPlayer(MainActivity.this);
|
|
|
|
+ videoPlayer.setActivity(this);
|
|
|
|
+ controlDelegate = new VideoControlDelegate(this, videoPlayer);
|
|
|
|
+ controlDelegate.subscribeData();
|
|
|
|
+ controlDelegate.getExitPlayingEvent().observe(this, aBoolean -> {
|
|
|
|
+ //判断视频是否播放完成,来判断是否要储存上次播放时间
|
|
|
|
+ videoPlayer.storeLastPlayTime();
|
|
|
|
+
|
|
|
|
+ if (hadFloatVideo) {
|
|
|
|
+ videoPlayer.hideAllWidget();
|
|
|
|
+ changeVideo2Float();
|
|
|
|
+ } else {
|
|
|
|
+ destroyVideo();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ controlDelegate.getPlayNextEvent().observe(this, playNext -> {
|
|
|
|
+ Logger.d("请求下一个视频 %s", playNext);
|
|
|
|
+ if(playNext != null && playNext) {
|
|
|
|
+ AndroidToJS.evaluateJavascript(getWebView(), AndroidToJS.JS_EVENT_PLAY_NEXT);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ videoPlayer.setOnPlayerPausedListener(controlDelegate);
|
|
|
|
+ }*/
|
|
|
|
+
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
protected void destroyVideoView() {
|
|
protected void destroyVideoView() {
|
|
destroyVideo();
|
|
destroyVideo();
|
|
@@ -182,10 +225,7 @@ public class MainActivity extends BaseWebActivity implements AndroidToJS.PlayVid
|
|
@Override
|
|
@Override
|
|
public void playFloatVideo(final String url, final int x, final int y, final int width, final int height,
|
|
public void playFloatVideo(final String url, final int x, final int y, final int width, final int height,
|
|
final String uid, final String sourceId, final String title, boolean needMute) {
|
|
final String uid, final String sourceId, final String title, boolean needMute) {
|
|
- if(url.isEmpty() || url == null){
|
|
|
|
- Toast.makeText(this,"视频链接错误!",Toast.LENGTH_SHORT).show();
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ //currentFloatInfo = new VideoInfo(url,x,y,width,height,uid,sourceId,title,needMute);
|
|
if(!hasShowWebView){
|
|
if(!hasShowWebView){
|
|
hasOneFloatViewToShow = true;
|
|
hasOneFloatViewToShow = true;
|
|
lastVideoInfo = new VideoInfo(url,x,y,width,height,uid,sourceId,title,needMute);
|
|
lastVideoInfo = new VideoInfo(url,x,y,width,height,uid,sourceId,title,needMute);
|
|
@@ -201,17 +241,16 @@ public class MainActivity extends BaseWebActivity implements AndroidToJS.PlayVid
|
|
@Override
|
|
@Override
|
|
public void playFullVideo(final String url, final String title, final String uid, final String sourceId, final long playTime,
|
|
public void playFullVideo(final String url, final String title, final String uid, final String sourceId, final long playTime,
|
|
final boolean hadFloatVideo, boolean showCompleteDialog, int seekTime) {
|
|
final boolean hadFloatVideo, boolean showCompleteDialog, int seekTime) {
|
|
- if(url.isEmpty() || url == null){
|
|
|
|
- Toast.makeText(this,"视频链接错误!",Toast.LENGTH_SHORT).show();
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
this.hadFloatVideo = hadFloatVideo;
|
|
this.hadFloatVideo = hadFloatVideo;
|
|
videoPlayer.setShowCompleteDialog(showCompleteDialog);
|
|
videoPlayer.setShowCompleteDialog(showCompleteDialog);
|
|
runOnUiThread(() -> {
|
|
runOnUiThread(() -> {
|
|
if (hadFloatVideo && TextUtils.isEmpty(url)) {
|
|
if (hadFloatVideo && TextUtils.isEmpty(url)) {
|
|
changeVideo2Full();
|
|
changeVideo2Full();
|
|
|
|
+ Log.d(TAG,"changeVideo2Full");
|
|
} else {
|
|
} else {
|
|
playVideo(url, title, uid, sourceId, playTime, seekTime);
|
|
playVideo(url, title, uid, sourceId, playTime, seekTime);
|
|
|
|
+ Log.d(TAG,"playVideo");
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -221,6 +260,7 @@ public class MainActivity extends BaseWebActivity implements AndroidToJS.PlayVid
|
|
* */
|
|
* */
|
|
|
|
|
|
public void favoritePlay(String sourceId,String title){
|
|
public void favoritePlay(String sourceId,String title){
|
|
|
|
+ videoPlayer.storeLastPlayTime();
|
|
String url = "http://112.35.32.145:8090/index.php?m=Home&c=Order&a=authorize&sourceId="
|
|
String url = "http://112.35.32.145:8090/index.php?m=Home&c=Order&a=authorize&sourceId="
|
|
+ sourceId + "&EpgServer=" + getUserEpgServer() + "&token=" + getUserToken();
|
|
+ sourceId + "&EpgServer=" + getUserEpgServer() + "&token=" + getUserToken();
|
|
new GetRequest().RequestAsync(url, new GetRequestListener() {
|
|
new GetRequest().RequestAsync(url, new GetRequestListener() {
|
|
@@ -257,6 +297,52 @@ public class MainActivity extends BaseWebActivity implements AndroidToJS.PlayVid
|
|
runOnUiThread(this::destroyVideo);
|
|
runOnUiThread(this::destroyVideo);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void webRequest(String tag, String url) {
|
|
|
|
+ Log.d(TAG,"webRequest,url:" + url);
|
|
|
|
+ MyRequest stringRequest = new MyRequest(com.android.volley.Request.Method.GET,url, new com.android.volley.Response.Listener<String>() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onResponse(String response) {
|
|
|
|
+ //Log.d(TAG,"访问成功,data:" + response);
|
|
|
|
+ backToWeb(tag,response);
|
|
|
|
+ }
|
|
|
|
+ }, new com.android.volley.Response.ErrorListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onErrorResponse(VolleyError error) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ Volley.newRequestQueue(this).add(stringRequest);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void backToWeb(String tag,String response){
|
|
|
|
+ String script = "javascript:onWebRequestResponse('"+tag+"','"+response+"')";
|
|
|
|
+ Log.d(TAG,script);
|
|
|
|
+ AndroidToJS.evaluateJavascript(getWebView(),"javascript:onWebRequestResponse('"+tag+"','"+response+"')");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ class MyRequest extends StringRequest {
|
|
|
|
+
|
|
|
|
+ public MyRequest(int method, String url, com.android.volley.Response.Listener<String> listener, @Nullable com.android.volley.Response.ErrorListener errorListener) {
|
|
|
|
+ super(method, url, listener, errorListener);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ protected com.android.volley.Response<String> parseNetworkResponse(NetworkResponse response) {
|
|
|
|
+ String parsed;
|
|
|
|
+ try {
|
|
|
|
+ parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers,"utf-8"));
|
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
|
+ // Since minSdkVersion = 8, we can't call
|
|
|
|
+ // new String(response.data, Charset.defaultCharset())
|
|
|
|
+ // So suppress the warning instead.
|
|
|
|
+ parsed = new String(response.data);
|
|
|
|
+ }
|
|
|
|
+ return com.android.volley.Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 全屏播放逻辑
|
|
* 全屏播放逻辑
|
|
*/
|
|
*/
|
|
@@ -353,6 +439,11 @@ public class MainActivity extends BaseWebActivity implements AndroidToJS.PlayVid
|
|
if (!isFullScreenVideo) {
|
|
if (!isFullScreenVideo) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (videoPlayer != null && videoPlayer.getWidth() == screenWidth) {
|
|
|
|
+ AndroidToJS.evaluateJavascript(getWebView(), AndroidToJS.JS_EVENT_PLAY_FINISH);
|
|
|
|
+ Log.d(TAG,"PLAY_FINISH");
|
|
|
|
+ }
|
|
if (videoPlayer != null) {
|
|
if (videoPlayer != null) {
|
|
isFullScreenVideo = false;
|
|
isFullScreenVideo = false;
|
|
controlDelegate.setFullVideo(false);
|
|
controlDelegate.setFullVideo(false);
|
|
@@ -363,6 +454,15 @@ public class MainActivity extends BaseWebActivity implements AndroidToJS.PlayVid
|
|
animChanged(0, floatVideoX, 0, floatVideoY,
|
|
animChanged(0, floatVideoX, 0, floatVideoY,
|
|
screenWidth, floatVideoWidth,
|
|
screenWidth, floatVideoWidth,
|
|
screenHeight, floatVideoHeight,false);
|
|
screenHeight, floatVideoHeight,false);
|
|
|
|
+
|
|
|
|
+ /* destroyVideo();
|
|
|
|
+
|
|
|
|
+ initMediaPlayer();
|
|
|
|
+
|
|
|
|
+ playVideo(currentFloatInfo.url,currentFloatInfo.title,currentFloatInfo.uid,currentFloatInfo.sourceId,
|
|
|
|
+ currentFloatInfo.x,currentFloatInfo.y,currentFloatInfo.width,currentFloatInfo.height,
|
|
|
|
+ currentFloatInfo.needMute);*/
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -396,15 +496,24 @@ public class MainActivity extends BaseWebActivity implements AndroidToJS.PlayVid
|
|
}
|
|
}
|
|
|
|
|
|
private void destroyVideo() {
|
|
private void destroyVideo() {
|
|
- isFullScreenVideo = false;
|
|
|
|
- controlDelegate.setFullVideo(false);
|
|
|
|
- if (videoPlayer != null && videoPlayer.getWidth() == screenWidth) {
|
|
|
|
-
|
|
|
|
- AndroidToJS.evaluateJavascript(getWebView(), AndroidToJS.JS_EVENT_PLAY_FINISH);
|
|
|
|
|
|
+ try{
|
|
|
|
+ isFullScreenVideo = false;
|
|
|
|
+ controlDelegate.setFullVideo(false);
|
|
|
|
+ if(videoPlayer == null){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (videoPlayer != null && videoPlayer.getWidth() == screenWidth) {
|
|
|
|
+ AndroidToJS.evaluateJavascript(getWebView(), AndroidToJS.JS_EVENT_PLAY_FINISH);
|
|
|
|
+ Log.d(TAG,"PLAY_FINISH");
|
|
|
|
+ }
|
|
|
|
+ videoPlayer.hideSeekContainer();
|
|
videoPlayer.onVideoPause();
|
|
videoPlayer.onVideoPause();
|
|
videoPlayer.onVideoDestroy();
|
|
videoPlayer.onVideoDestroy();
|
|
|
|
+
|
|
ViewGroup viewGroup = (ViewGroup) getWindow().getDecorView();
|
|
ViewGroup viewGroup = (ViewGroup) getWindow().getDecorView();
|
|
viewGroup.removeView(videoPlayer);
|
|
viewGroup.removeView(videoPlayer);
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -439,6 +548,7 @@ public class MainActivity extends BaseWebActivity implements AndroidToJS.PlayVid
|
|
Cursor cursor = getContentResolver().query(queryUri,new String[]{"value"},"name='user_token'",null,null);
|
|
Cursor cursor = getContentResolver().query(queryUri,new String[]{"value"},"name='user_token'",null,null);
|
|
cursor.moveToFirst();
|
|
cursor.moveToFirst();
|
|
String userToken = cursor.getString(cursor.getColumnIndexOrThrow("value"));
|
|
String userToken = cursor.getString(cursor.getColumnIndexOrThrow("value"));
|
|
|
|
+ //userToken = "Se48ja9jiqjq-Stjhd4izfd";
|
|
Log.d(TAG,"userToken:" + userToken);
|
|
Log.d(TAG,"userToken:" + userToken);
|
|
return userToken;
|
|
return userToken;
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
@@ -453,6 +563,7 @@ public class MainActivity extends BaseWebActivity implements AndroidToJS.PlayVid
|
|
Cursor cursor = getContentResolver().query(queryUri,new String[]{"value"},"name='epg_server'",null,null);
|
|
Cursor cursor = getContentResolver().query(queryUri,new String[]{"value"},"name='epg_server'",null,null);
|
|
cursor.moveToFirst();
|
|
cursor.moveToFirst();
|
|
String epgServer = cursor.getString(cursor.getColumnIndexOrThrow("value"));
|
|
String epgServer = cursor.getString(cursor.getColumnIndexOrThrow("value"));
|
|
|
|
+ //epgServer = "http://111.20.42.163:33200";
|
|
Log.d(TAG,"epgServer:" + epgServer);
|
|
Log.d(TAG,"epgServer:" + epgServer);
|
|
return epgServer;
|
|
return epgServer;
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|