Skip to content

Commit

Permalink
style: spotify embed player
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed May 12, 2024
1 parent 241a32b commit 2f5cd87
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
28 changes: 28 additions & 0 deletions TMessagesProj/src/main/assets/spotify_embed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<style>
body { margin: 0; width:100%%; height:100%%; background-color:#000; }
html { width:100%%; height:100%%; background-color:#000; }
.embed-container iframe,
.embed-container object,
.embed-container embed {
position: absolute;
top: 0;
left: 0;
width: 100%% !important;
height: 100%% !important;
}
</style>
</head>
<body>
<div class="embed-container">
<iframe
style="border-radius:12px"
src="%1$s"
width="100%%" height="100%%" frameBorder="0" allowfullscreen=""
allow="autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture">
</iframe>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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];

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down

0 comments on commit 2f5cd87

Please sign in to comment.