From 9f644537996888b979cdd68bbaebedb81c2b67f4 Mon Sep 17 00:00:00 2001 From: okjackcaptain <378702538@qq.com> Date: Wed, 5 Oct 2022 09:59:41 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E7=9B=B4=E6=92=AD=E7=9B=B8=E5=85=B3bug?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20-=20=E5=97=85=E6=8E=A2=E9=80=9F=E5=BA=A6?= =?UTF-8?q?=E4=BC=98=E5=8C=96=20-=20=E5=88=86=E7=B1=BB=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E9=A1=B5=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../osc/player/controller/VodController.java | 14 +++-- .../tvbox/osc/ui/activity/PlayActivity.java | 53 ++++++++++++++++-- .../tvbox/osc/ui/fragment/GridFragment.java | 19 +++++-- .../tvbox/osc/ui/fragment/PlayFragment.java | 55 ++++++++++++++++--- .../github/tvbox/osc/util/DefaultConfig.java | 17 ++++-- .../tvbox/osc/util/VideoParseRuler.java | 2 +- .../res/layout/player_vod_control_view.xml | 1 + 7 files changed, 132 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/com/github/tvbox/osc/player/controller/VodController.java b/app/src/main/java/com/github/tvbox/osc/player/controller/VodController.java index 80d331d3..31543a64 100644 --- a/app/src/main/java/com/github/tvbox/osc/player/controller/VodController.java +++ b/app/src/main/java/com/github/tvbox/osc/player/controller/VodController.java @@ -113,14 +113,16 @@ public class VodController extends BaseController { TextView mNextBtn; TextView mPreBtn; TextView mPlayerScaleBtn; - TextView mPlayerSpeedBtn; + public TextView mPlayerSpeedBtn; TextView mPlayerBtn; TextView mPlayerIJKBtn; TextView mPlayerRetry; TextView mPlayrefresh; - TextView mPlayerTimeStartBtn; - TextView mPlayerTimeSkipBtn; - TextView mPlayerTimeStepBtn; + public TextView mPlayerTimeStartEndText; + public TextView mPlayerTimeStartBtn; + public TextView mPlayerTimeSkipBtn; + public TextView mPlayerTimeStepBtn; + public TextView mPlayerTimeResetBtn; TextView mPlayPauseTime; TextView mPlayLoadNetSpeed; TextView mVideoSize; @@ -179,9 +181,11 @@ public class VodController extends BaseController { mPlayerSpeedBtn = findViewById(R.id.play_speed); mPlayerBtn = findViewById(R.id.play_player); mPlayerIJKBtn = findViewById(R.id.play_ijk); + mPlayerTimeStartEndText = findViewById(R.id.play_time_start_end_text); mPlayerTimeStartBtn = findViewById(R.id.play_time_start); mPlayerTimeSkipBtn = findViewById(R.id.play_time_end); mPlayerTimeStepBtn = findViewById(R.id.play_time_step); + mPlayerTimeResetBtn = findViewById(R.id.play_time_reset); mPlayPauseTime = findViewById(R.id.tv_sys_time); mPlayLoadNetSpeed = findViewById(R.id.tv_play_load_net_speed); mVideoSize = findViewById(R.id.tv_videosize); @@ -463,7 +467,7 @@ public class VodController extends BaseController { } }); // 增加播放页面片头片尾时间重置 - findViewById(R.id.play_time_reset).setOnClickListener(new OnClickListener() { + mPlayerTimeResetBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { myHandle.removeCallbacks(myRunnable); diff --git a/app/src/main/java/com/github/tvbox/osc/ui/activity/PlayActivity.java b/app/src/main/java/com/github/tvbox/osc/ui/activity/PlayActivity.java index f99f8843..a0214ad5 100644 --- a/app/src/main/java/com/github/tvbox/osc/ui/activity/PlayActivity.java +++ b/app/src/main/java/com/github/tvbox/osc/ui/activity/PlayActivity.java @@ -111,6 +111,8 @@ public class PlayActivity extends BaseActivity { 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 PlayActivity extends BaseActivity { 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 PlayActivity extends BaseActivity { @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) { @@ -1360,7 +1380,6 @@ public class PlayActivity extends BaseActivity { } WebResourceResponse checkIsVideo(String url, HashMap 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); @@ -1409,11 +1428,19 @@ public class PlayActivity extends BaseActivity { @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 webHeaders = new HashMap<>(); try { @@ -1421,6 +1448,7 @@ public class PlayActivity extends BaseActivity { 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)); } @@ -1542,6 +1570,18 @@ public class PlayActivity extends BaseActivity { } return null; } + //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); @@ -1557,6 +1597,7 @@ public class PlayActivity extends BaseActivity { 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)); } diff --git a/app/src/main/java/com/github/tvbox/osc/ui/fragment/GridFragment.java b/app/src/main/java/com/github/tvbox/osc/ui/fragment/GridFragment.java index 88d655cf..8d259665 100644 --- a/app/src/main/java/com/github/tvbox/osc/ui/fragment/GridFragment.java +++ b/app/src/main/java/com/github/tvbox/osc/ui/fragment/GridFragment.java @@ -253,6 +253,14 @@ public class GridFragment extends BaseLazyFragment { } page++; maxPage = absXml.movie.pagecount; + + if (page > maxPage) { + gridAdapter.loadMoreEnd(); + gridAdapter.setEnableLoadMore(false); + } else { + gridAdapter.loadMoreComplete(); + gridAdapter.setEnableLoadMore(true); + } } else { if(page == 1){ showEmpty(); @@ -260,11 +268,12 @@ public class GridFragment extends BaseLazyFragment { if(page > maxPage){ Toast.makeText(getContext(), "没有更多了", Toast.LENGTH_SHORT).show(); } - } - if (page > maxPage) { - gridAdapter.loadMoreEnd(); - } else { - gridAdapter.loadMoreComplete(); + if (page > maxPage) { + gridAdapter.loadMoreEnd(); + } else { + gridAdapter.loadMoreComplete(); + } + gridAdapter.setEnableLoadMore(false); } } }); diff --git a/app/src/main/java/com/github/tvbox/osc/ui/fragment/PlayFragment.java b/app/src/main/java/com/github/tvbox/osc/ui/fragment/PlayFragment.java index 1170d51a..76bc4514 100644 --- a/app/src/main/java/com/github/tvbox/osc/ui/fragment/PlayFragment.java +++ b/app/src/main/java/com/github/tvbox/osc/ui/fragment/PlayFragment.java @@ -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 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 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)); } diff --git a/app/src/main/java/com/github/tvbox/osc/util/DefaultConfig.java b/app/src/main/java/com/github/tvbox/osc/util/DefaultConfig.java index df6cf53c..75d662c9 100644 --- a/app/src/main/java/com/github/tvbox/osc/util/DefaultConfig.java +++ b/app/src/main/java/com/github/tvbox/osc/util/DefaultConfig.java @@ -109,20 +109,27 @@ public class DefaultConfig { //增加对flv|avi|mkv|rm|wmv|mpg等几种视频格式的支持 //private static final Pattern snifferMatch = Pattern.compile("http((?!http).){26,}?\\.(m3u8|mp4)\\?.*|http((?!http).){26,}\\.(m3u8|mp4)|http((?!http).){26,}?/m3u8\\?pt=m3u8.*|http((?!http).)*?default\\.ixigua\\.com/.*|http((?!http).)*?cdn-tos[^\\?]*|http((?!http).)*?/obj/tos[^\\?]*|http.*?/player/m3u8play\\.php\\?url=.*|http.*?/player/.*?[pP]lay\\.php\\?url=.*|http.*?/playlist/m3u8/\\?vid=.*|http.*?\\.php\\?type=m3u8&.*|http.*?/download.aspx\\?.*|http.*?/api/up_api.php\\?.*|https.*?\\.66yk\\.cn.*|http((?!http).)*?netease\\.com/file/.*"); private static final Pattern snifferMatch = Pattern.compile("http((?!http).)*?default\\.365yg\\.com/.*|http((?!http).){20,}?/m3u8\\?pt=m3u8.*|http((?!http).)*?default\\.ixigua\\.com/.*|http((?!http).)*?dycdn-tos\\.pstatp[^\\?]*|http.*?/player/m3u8play\\.php\\?url=.*|http.*?/playlist/m3u8/\\?vid=.*|http.*?\\.php\\?type=m3u8&.*|http.*?/download.aspx\\?.*|http.*?/api/up_api.php\\?.*|https.*?\\.66yk\\.cn.*|http((?!http).)*?netease\\.com/file/.*"); - private static final Pattern normalSnifferMatch = Pattern.compile("http((?!http).){20,}?\\.(m3u8|mp4|flv|avi|mkv|rm|wmv|mpg)\\?.*|http((?!http).){20,}\\.(m3u8|mp4|flv|avi|mkv|rm|wmv|mpg)"); + private static final String[] videoSubfix = {"m3u8","mp4","flv","avi","mkv","rm","wmv","mpg"}; public static boolean isVideoFormat(String url) { if (url.contains("=http")) { return false; } Uri uri = Uri.parse(url); - if (uri.getPath().endsWith(".js") || uri.getPath().endsWith(".css") || uri.getPath().endsWith(".html")) { + String path = uri.getPath(); + if (path == null || path.isEmpty()) { return false; } - if (uri.getQuery().startsWith("http")) { + if (path.endsWith(".js") || path.endsWith(".css") || path.endsWith(".html")) { return false; } - if (normalSnifferMatch.matcher(url).find()) { - return true; + String query = uri.getQuery(); + if (query != null && query.startsWith("http")) { + return false; + } + for(String oneSubfix : videoSubfix) { + if (path.endsWith("." + oneSubfix)) { + return true; + } } if (snifferMatch.matcher(url).find()) { return true; diff --git a/app/src/main/java/com/github/tvbox/osc/util/VideoParseRuler.java b/app/src/main/java/com/github/tvbox/osc/util/VideoParseRuler.java index 05c01ac0..0dff5f55 100644 --- a/app/src/main/java/com/github/tvbox/osc/util/VideoParseRuler.java +++ b/app/src/main/java/com/github/tvbox/osc/util/VideoParseRuler.java @@ -47,7 +47,7 @@ public class VideoParseRuler { } return isVideo; } catch (Exception e) { - + e.printStackTrace(); } return false; } diff --git a/app/src/main/res/layout/player_vod_control_view.xml b/app/src/main/res/layout/player_vod_control_view.xml index cc6464f8..e9922fc2 100644 --- a/app/src/main/res/layout/player_vod_control_view.xml +++ b/app/src/main/res/layout/player_vod_control_view.xml @@ -254,6 +254,7 @@ android:textSize="@dimen/ts_20" />