From 2f5cd879c52cf61fd4dd86cbdc1847ad0251fa1b Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sun, 12 May 2024 13:35:51 +0800 Subject: [PATCH] style: spotify embed player --- .../src/main/assets/spotify_embed.html | 28 +++++++++++++++++++ .../ui/Components/EmbedBottomSheet.java | 27 +++++++++++++++++- .../telegram/ui/Components/WebPlayerView.java | 7 +++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 TMessagesProj/src/main/assets/spotify_embed.html diff --git a/TMessagesProj/src/main/assets/spotify_embed.html b/TMessagesProj/src/main/assets/spotify_embed.html new file mode 100644 index 0000000000..1df6e439c1 --- /dev/null +++ b/TMessagesProj/src/main/assets/spotify_embed.html @@ -0,0 +1,28 @@ + + + + + + +
+ +
+ + \ No newline at end of file diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/EmbedBottomSheet.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/EmbedBottomSheet.java index be862667a7..c49ca5264e 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/EmbedBottomSheet.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/EmbedBottomSheet.java @@ -64,6 +64,8 @@ import org.telegram.ui.LaunchActivity; import org.telegram.ui.PhotoViewer; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; import java.util.HashMap; import java.util.Locale; @@ -83,6 +85,7 @@ public class EmbedBottomSheet extends BottomSheet { private FrameLayout containerLayout; private ImageView pipButton; private boolean isYouTube; + private boolean isSpotify; private int[] position = new int[2]; @@ -260,6 +263,10 @@ private EmbedBottomSheet(Context context, String title, String description, Stri width = AndroidUtilities.displaySize.x; height = AndroidUtilities.displaySize.y / 2; } + isSpotify = WebPlayerView.isSpotify(embedUrl); + if (isSpotify) { + height -= 200; + } fullscreenVideoContainer = new FrameLayout(context); fullscreenVideoContainer.setKeepScreenOn(true); @@ -764,7 +771,13 @@ public ViewGroup getTextureViewContainer() { return; } boolean animated = false; - if (PipVideoOverlay.show(inAppOnly, parentActivity, webView, width, height)) { + int newWidth = width; + int newHeight = height; + if (isSpotify) { + newWidth = 600; + newHeight = 200; + } + if (PipVideoOverlay.show(inAppOnly, parentActivity, webView, newWidth, newHeight)) { PipVideoOverlay.setParentSheet(EmbedBottomSheet.this); } @@ -892,6 +905,7 @@ public void onOpenAnimationEnd() { args.put("Referer", "messenger.telegram.org"); try { String currentYoutubeId = videoView.getYoutubeId(); + boolean isSpotify = WebPlayerView.isSpotify(embedUrl); if (currentYoutubeId != null) { progressBarBlackBackground.setVisibility(View.VISIBLE); isYouTube = true; @@ -922,6 +936,17 @@ public void onOpenAnimationEnd() { } } webView.loadDataWithBaseURL("https://messenger.telegram.org/", String.format(Locale.US, youtubeFrame, currentYoutubeId, seekToTime), "text/html", "UTF-8", "https://youtube.com"); + } else if (isSpotify) { + InputStream in = getContext().getAssets().open("spotify_embed.html"); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + byte[] buffer = new byte[10240]; + int c; + while ((c = in.read(buffer)) != -1) { + bos.write(buffer, 0, c); + } + bos.close(); + in.close(); + webView.loadDataWithBaseURL("https://messenger.telegram.org/", String.format(Locale.US, bos.toString("UTF-8"), embedUrl), "text/html", "UTF-8", "https://open.spotify.com"); } else { webView.loadUrl(embedUrl, args); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/WebPlayerView.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/WebPlayerView.java index 1007f9075c..e7d95a5b5e 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/WebPlayerView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/WebPlayerView.java @@ -2095,6 +2095,13 @@ public static String getYouTubeVideoId(String url) { return id; } + public static boolean isSpotify(String url) { + if (url != null && url.startsWith("https://embed.spotify.com/")) { + return true; + } + return false; + } + public boolean canHandleUrl(String url) { if (url != null) { if (url.endsWith(".mp4")) {