|
|
|
|
@ -111,6 +111,8 @@ public class PlayFragment extends BaseLazyFragment { |
|
|
|
|
private SourceViewModel sourceViewModel; |
|
|
|
|
private Handler mHandler; |
|
|
|
|
|
|
|
|
|
private long videoDuration = -1; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected int getLayoutResID() { |
|
|
|
|
return R.layout.activity_play; |
|
|
|
|
@ -147,6 +149,11 @@ public class PlayFragment extends BaseLazyFragment { |
|
|
|
|
ProgressManager progressManager = new ProgressManager() { |
|
|
|
|
@Override |
|
|
|
|
public void saveProgress(String url, long progress) { |
|
|
|
|
if (videoDuration != -1) { |
|
|
|
|
if (videoDuration <= 6000) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
CacheManager.save(MD5.string2MD5(url), progress); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -223,11 +230,24 @@ public class PlayFragment extends BaseLazyFragment { |
|
|
|
|
@Override |
|
|
|
|
public void prepared() { |
|
|
|
|
initSubtitleView(); |
|
|
|
|
initVideoDurationSomeThing(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
mVideoView.setVideoController(mController); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void initVideoDurationSomeThing() { |
|
|
|
|
videoDuration = mVideoView.getMediaPlayer().getDuration(); |
|
|
|
|
if (videoDuration <= 6000) { |
|
|
|
|
mController.mPlayerSpeedBtn.setVisibility(View.GONE); |
|
|
|
|
mController.mPlayerTimeStartEndText.setVisibility(View.GONE); |
|
|
|
|
mController.mPlayerTimeStartBtn.setVisibility(View.GONE); |
|
|
|
|
mController.mPlayerTimeSkipBtn.setVisibility(View.GONE); |
|
|
|
|
mController.mPlayerTimeStepBtn.setVisibility(View.GONE); |
|
|
|
|
mController.mPlayerTimeResetBtn.setVisibility(View.GONE); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//设置字幕
|
|
|
|
|
void setSubtitle(String path) { |
|
|
|
|
if (path != null && path .length() > 0) { |
|
|
|
|
@ -1384,7 +1404,6 @@ public class PlayFragment extends BaseLazyFragment { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
WebResourceResponse checkIsVideo(String url, HashMap<String, String> headers) { |
|
|
|
|
LOG.i("shouldInterceptRequest url:" + url); |
|
|
|
|
if (url.endsWith("/favicon.ico")) { |
|
|
|
|
if (url.startsWith("http://127.0.0.1")) { |
|
|
|
|
return new WebResourceResponse("image/x-icon", "UTF-8", null); |
|
|
|
|
@ -1433,11 +1452,19 @@ public class PlayFragment extends BaseLazyFragment { |
|
|
|
|
@Override |
|
|
|
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP) |
|
|
|
|
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) { |
|
|
|
|
String url = ""; |
|
|
|
|
try { |
|
|
|
|
url = request.getUrl().toString(); |
|
|
|
|
} catch (Throwable th) { |
|
|
|
|
|
|
|
|
|
String url = request.getUrl().toString(); |
|
|
|
|
LOG.i("shouldInterceptRequest url:" + url); |
|
|
|
|
//css与jpg等无效资源避免请求远程直接返回response
|
|
|
|
|
String uselessmMimeType = null; |
|
|
|
|
if (url.contains(".css")) { |
|
|
|
|
uselessmMimeType = "text/css"; |
|
|
|
|
} else if (url.contains(".jpg")) { |
|
|
|
|
uselessmMimeType = "image/jpeg"; |
|
|
|
|
} else if (url.contains(".png")) { |
|
|
|
|
uselessmMimeType = "image/png"; |
|
|
|
|
} |
|
|
|
|
if (uselessmMimeType != null && !uselessmMimeType.isEmpty()) { |
|
|
|
|
return new WebResourceResponse(uselessmMimeType, "UTF-8", null); |
|
|
|
|
} |
|
|
|
|
HashMap<String, String> webHeaders = new HashMap<>(); |
|
|
|
|
try { |
|
|
|
|
@ -1445,6 +1472,7 @@ public class PlayFragment extends BaseLazyFragment { |
|
|
|
|
for (String k : hds.keySet()) { |
|
|
|
|
if (k.equalsIgnoreCase("user-agent") |
|
|
|
|
|| k.equalsIgnoreCase("referer") |
|
|
|
|
|| k.equalsIgnoreCase("accept") |
|
|
|
|
|| k.equalsIgnoreCase("origin")) { |
|
|
|
|
webHeaders.put(k, hds.get(k)); |
|
|
|
|
} |
|
|
|
|
@ -1558,6 +1586,7 @@ public class PlayFragment extends BaseLazyFragment { |
|
|
|
|
@Override |
|
|
|
|
public XWalkWebResourceResponse shouldInterceptLoadRequest(XWalkView view, XWalkWebResourceRequest request) { |
|
|
|
|
String url = request.getUrl().toString(); |
|
|
|
|
LOG.i("shouldInterceptLoadRequest url:" + url); |
|
|
|
|
// suppress favicon requests as we don't display them anywhere
|
|
|
|
|
if (url.endsWith("/favicon.ico")) { |
|
|
|
|
if (url.startsWith("http://127.0.0.1")) { |
|
|
|
|
@ -1565,7 +1594,18 @@ public class PlayFragment extends BaseLazyFragment { |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
LOG.i("shouldInterceptLoadRequest url:" + url); |
|
|
|
|
//css与jpg等无效资源避免请求远程直接返回response
|
|
|
|
|
String uselessmMimeType = null; |
|
|
|
|
if (url.contains(".css")) { |
|
|
|
|
uselessmMimeType = "text/css"; |
|
|
|
|
} else if (url.contains(".jpg")) { |
|
|
|
|
uselessmMimeType = "image/jpeg"; |
|
|
|
|
} else if (url.contains(".png")) { |
|
|
|
|
uselessmMimeType = "image/png"; |
|
|
|
|
} |
|
|
|
|
if (uselessmMimeType != null && !uselessmMimeType.isEmpty()) { |
|
|
|
|
return createXWalkWebResourceResponse(uselessmMimeType, "UTF-8", null); |
|
|
|
|
} |
|
|
|
|
boolean ad; |
|
|
|
|
if (!loadedUrls.containsKey(url)) { |
|
|
|
|
ad = AdBlocker.isAd(url); |
|
|
|
|
@ -1581,6 +1621,7 @@ public class PlayFragment extends BaseLazyFragment { |
|
|
|
|
for (String k : hds.keySet()) { |
|
|
|
|
if (k.equalsIgnoreCase("user-agent") |
|
|
|
|
|| k.equalsIgnoreCase("referer") |
|
|
|
|
|| k.equalsIgnoreCase("accept") |
|
|
|
|
|| k.equalsIgnoreCase("origin")) { |
|
|
|
|
webHeaders.put(k, hds.get(k)); |
|
|
|
|
} |
|
|
|
|
|