Skip to content

Commit

Permalink
Update MainActivity.java
Browse files Browse the repository at this point in the history
  • Loading branch information
prateek-chaubey authored Feb 4, 2025
1 parent f3d023c commit 6cf60b7
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions app/src/main/java/com/google/android/youtube/pro/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -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));
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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) {
Expand Down

0 comments on commit 6cf60b7

Please sign in to comment.