diff --git a/app/src/main/java/com/google/android/youtube/pro/MainActivity.java b/app/src/main/java/com/google/android/youtube/pro/MainActivity.java index fb44f13..9d5059e 100644 --- a/app/src/main/java/com/google/android/youtube/pro/MainActivity.java +++ b/app/src/main/java/com/google/android/youtube/pro/MainActivity.java @@ -77,11 +77,14 @@ public void onPageStarted(WebView p1, String p2, Bitmap p3) { public void onPageFinished(WebView p1, String url) { - web.loadUrl("javascript:if (window.trustedTypes && window.trustedTypes.createPolicy) {window.trustedTypes.createPolicy('default', {createHTML: (string) => string,createScriptURL: string => string, createScript: string => string, });}"); + web.loadUrl("javascript:if (window.trustedTypes && window.trustedTypes.createPolicy && !window.trustedTypes.defaultPolicy) {window.trustedTypes.createPolicy('default', {createHTML: (string) => string,createScriptURL: string => string, createScript: string => string, });}"); web.loadUrl("javascript:(function () { var script = document.createElement('script'); script.src='https://cdn.jsdelivr.net/npm/ytpro'; document.body.appendChild(script); })();"); web.loadUrl("javascript:(function () { var script = document.createElement('script'); script.src='https://cdn.jsdelivr.net/npm/ytpro/bgplay.js'; document.body.appendChild(script); })();"); if(dl){ - web.loadUrl("javascript:(function () {window.location.hash='download';})();"); + + //Will Patch this later + + //web.loadUrl("javascript:(function () {window.location.hash='download';})();"); //dL=false; } if(!url.contains("#bgplay") && isPlaying){ @@ -276,11 +279,10 @@ public String getInfo() { @JavascriptInterface public void bgStart(String iconn , String titlen , String subtitlen,long dura) { -// ForegroundService.setupNotification( - icon =iconn; - title =titlen; + icon=iconn; + title=titlen; subtitle=subtitlen; - duration= dura; + duration=dura; isPlaying=true; Intent intent = new Intent(getApplicationContext(), ForegroundService.class); @@ -300,8 +302,8 @@ public void bgStart(String iconn , String titlen , String subtitlen,long dura) { public void bgUpdate(String iconn , String titlen , String subtitlen,long dura) { - icon =iconn; - title =titlen; + icon=iconn; + title=titlen; subtitle=subtitlen; duration=(long)(dura); @@ -318,8 +320,6 @@ public void bgUpdate(String iconn , String titlen , String subtitlen,long dura) } @JavascriptInterface public void bgStop() { - Log.e("hii","stop"); - isPlaying=false; stopService(new Intent(getApplicationContext(), ForegroundService.class)); @@ -329,11 +329,8 @@ public void bgStop() { } @JavascriptInterface public void bgPause(long ct) { - Log.e("hii","pause"); -//ForegroundService.updateNotification(icon,title,subtitle,"play", getApplicationContext(),duration,ct); - getApplicationContext().sendBroadcast(new Intent("UPDATE_NOTIFICATION") .putExtra("icon", icon) .putExtra("title", title) @@ -346,9 +343,6 @@ public void bgPause(long ct) { } @JavascriptInterface public void bgPlay(long ct) { - Log.e("hii","play"); -//ForegroundService.updateNotification(icon,title,subtitle,"pause",getApplicationContext(),duration,ct); - getApplicationContext().sendBroadcast(new Intent("UPDATE_NOTIFICATION") .putExtra("icon", icon) @@ -362,9 +356,6 @@ public void bgPlay(long ct) { } @JavascriptInterface public void bgBuffer(long ct) { - Log.e("hii","play"); -//ForegroundService.updateNotification(icon,title,subtitle,"buffer",getApplicationContext(),duration,ct); - getApplicationContext().sendBroadcast(new Intent("UPDATE_NOTIFICATION") .putExtra("icon", icon) @@ -376,6 +367,16 @@ public void bgBuffer(long ct) { ); + } + @JavascriptInterface + public void fetchYouTubeData(String videoId,final boolean bgplay) { + new Thread(() -> { + JSONObject response = YoutubeRequest.getData(videoId,false); + if (response != null) { + String jsonResponse = response.toString(); + runOnUiThread(() -> web.evaluateJavascript("callbackVideoResponse(" + jsonResponse + ","+bgplay+")", null)); + } + }).start(); } @JavascriptInterface public void pipvid(String x) {