Skip to content

Commit

Permalink
youtube player
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaji Khan committed Jan 11, 2025
1 parent ad3c22e commit 7063b6c
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ dependencies {

// round seekbar

implementation 'com.google.oboe:oboe:1.9.0'
implementation 'com.google.oboe:oboe:1.9.3'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
Log.d(TAG, "onPageFinished: " + url);
webView.evaluateJavascript("JSON.parse (document.forms [1].children[2].value)[0].downloadUrl\n", new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
Log.d(TAG, "onReceiveValue: " + value);
}
});
// String js = "(function () {return JSON.parse (document.forms [1].children[2].value)[0].downloadUrl})()";
// webView.evaluateJavascript(js, new ValueCallback<String>() {
// @Override
// public void onReceiveValue(String value) {
// Log.d(TAG, "onReceiveValue: " + value);
// }
// });
}
});

Expand Down
73 changes: 73 additions & 0 deletions app/src/main/java/com/shajikhan/ladspa/amprack/Rack.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.shajikhan.ladspa.amprack;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.ColorStateList;
Expand All @@ -20,6 +21,8 @@
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
Expand Down Expand Up @@ -75,6 +78,7 @@
public class Rack extends Fragment {
MainActivity mainActivity ;
LinearProgressIndicator quickPatchProgress ;
Dialog youtubePlayer ;
String TAG = getClass().getSimpleName();
PopupMenu optionsMenu ;
ToggleButton toggleVideo, videoRecord ;
Expand Down Expand Up @@ -654,6 +658,7 @@ public boolean onMenuItemClick(@NonNull MenuItem item) {
});

MenuItem nam = optionsMenu.getMenu().findItem(R.id.nam);
nam.setVisible(false);
nam.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(@NonNull MenuItem item) {
Expand All @@ -662,6 +667,16 @@ public boolean onMenuItemClick(@NonNull MenuItem item) {
}
});

MenuItem ytMenu = optionsMenu.getMenu().findItem(R.id.youtube);
ytMenu.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(@NonNull MenuItem item) {
youtubePlayer.show();
// ((WebView) youtubePlayer.findViewById(R.id.webview)).loadUrl("https://youtube.com");
return false;
}
});

MenuItem exit_item = optionsMenu.getMenu().findItem(R.id.menu_exit);
exit_item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
Expand Down Expand Up @@ -1127,6 +1142,64 @@ public void onClick(View v) {
// mixerLabel.setBackgroundColor(getResources().getColor(R.color.wheat));
}

youtubePlayer = new Dialog(mainActivity);
youtubePlayer.setContentView(mainActivity.getLayoutInflater().inflate(R.layout.youtube, null));

WebView yt = youtubePlayer.findViewById(R.id.webview);
yt.getSettings().setJavaScriptEnabled(true);
yt.getSettings().setDomStorageEnabled(true);
yt.setWebViewClient(new WebViewClient());

((Button)(youtubePlayer.findViewById(R.id.patch_up))).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
patchUp.performClick();
}
});

((Button)(youtubePlayer.findViewById(R.id.reload))).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((WebView) youtubePlayer.findViewById(R.id.webview)).reload();
}
});

((Button)(youtubePlayer.findViewById(R.id.prev))).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((WebView) youtubePlayer.findViewById(R.id.webview)).goBack();
}
});

((Button)(youtubePlayer.findViewById(R.id.next))).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((WebView) youtubePlayer.findViewById(R.id.webview)).goForward();
}
});

((Button)(youtubePlayer.findViewById(R.id.close))).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
youtubePlayer.hide();
}
});

((Button)(youtubePlayer.findViewById(R.id.power))).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mainActivity.onOff.performClick();
}
});

((Button)(youtubePlayer.findViewById(R.id.patch_down))).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
patchDown.performClick();
}
});

yt.loadUrl("https://youtube.com");
}

public void saveBugReport (AlertDialog dialog, String title, String description, String email, boolean notify) {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/baseline_power_settings_new_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M13,3h-2v10h2L13,3zM17.83,5.17l-1.42,1.42C17.99,7.86 19,9.81 19,12c0,3.87 -3.13,7 -7,7s-7,-3.13 -7,-7c0,-2.19 1.01,-4.14 2.58,-5.42L6.17,5.17C4.23,6.82 3,9.26 3,12c0,4.97 4.03,9 9,9s9,-4.03 9,-9c0,-2.74 -1.23,-5.18 -3.17,-6.83z"/>

</vector>
87 changes: 87 additions & 0 deletions app/src/main/res/layout/youtube.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:minHeight="500dp"
android:layout_height="match_parent">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Patch"
android:textAlignment="center"
android:layout_gravity="center"
android:fontFamily="@font/gruppo"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal">
<Button
android:layout_width="36dp"
android:padding="5dp"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/baseline_power_settings_new_24"
android:id="@+id/power"/>
<Button
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_baseline_keyboard_arrow_up_24"
android:text="Up"
android:id="@+id/patch_up"/>
<Button
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_baseline_keyboard_arrow_down_24"
android:text="Down"
android:id="@+id/patch_down"/>
</LinearLayout>


<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:id="@+id/webview"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_baseline_arrow_back_ios_new_24"
android:id="@+id/prev"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/sync"
android:layout_marginLeft="5dp"
android:id="@+id/reload"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:drawableLeft="@drawable/ic_baseline_arrow_forward_ios_24"
android:id="@+id/next"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_gravity="end"
android:gravity="end"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/close"
android:text="Close"
android:layout_gravity="right"
android:drawableLeft="@drawable/baseline_close_24"
android:layout_marginLeft="5dp"/>
</LinearLayout>
</LinearLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/menu/options_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
android:icon="@drawable/baseline_sync_24"
android:title="Sync with PC / Smart Pedal"/>

<item android:id="@+id/youtube"
android:title="Play with YouTube Video"/>
<item android:id="@+id/nam"
android:title="NAM Model Downloader"/>
<item android:id="@+id/menu_exit"
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ buildscript {

plugins {
id 'com.google.firebase.crashlytics' version '2.9.9' apply false
id 'com.android.application' version '8.7.2' apply false
id 'com.android.library' version '8.7.2' apply false
id 'com.android.application' version '8.8.0' apply false
id 'com.android.library' version '8.8.0' apply false
id 'com.google.gms.google-services' version '4.3.10' apply false

// id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Feb 22 15:33:56 IST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

0 comments on commit 7063b6c

Please sign in to comment.