Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ class InternetRadioStationCache(
var streamUrl: String? = null,
@ColumnInfo(name = "home_page_url")
var homePageUrl: String? = null,
@ColumnInfo(name = "cover_art")
var coverArtId: String? = null,
) {
constructor(station: InternetRadioStation) : this(
id = station.id ?: "",
name = station.name,
streamUrl = station.streamUrl,
homePageUrl = station.homePageUrl,
coverArtId = station.coverArtId,
)

fun toInternetRadioStation(): InternetRadioStation {
Expand All @@ -32,6 +35,7 @@ class InternetRadioStationCache(
name = name,
streamUrl = streamUrl,
homePageUrl = homePageUrl,
coverArtId = coverArtId,
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.cappielloantonio.tempo.model

import android.content.ContentResolver
import android.net.Uri
import android.os.Bundle
import androidx.annotation.Keep
Expand All @@ -13,7 +12,6 @@ import androidx.media3.common.util.UnstableApi
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.cappielloantonio.tempo.glide.CustomGlideRequest
import com.cappielloantonio.tempo.provider.AlbumArtContentProvider
import androidx.room.Embedded
import com.cappielloantonio.tempo.subsonic.models.Child
Expand Down Expand Up @@ -202,15 +200,7 @@ class SessionMediaItem() {
title = internetRadioStation.name
streamUrl = internetRadioStation.streamUrl
type = Constants.MEDIA_TYPE_RADIO

val homePageUrl = internetRadioStation.homePageUrl
if (homePageUrl != null && homePageUrl.isNotEmpty() && MusicUtil.isImageUrl(homePageUrl)) {
val encodedUrl = android.util.Base64.encodeToString(
homePageUrl.toByteArray(java.nio.charset.StandardCharsets.UTF_8),
android.util.Base64.URL_SAFE or android.util.Base64.NO_WRAP
)
coverArtId = "ir_$encodedUrl"
}
coverArtId = internetRadioStation.coverArtId
}

fun getMediaItem(): MediaItem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import android.database.Cursor;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.util.Base64;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

Expand Down Expand Up @@ -54,15 +52,7 @@ public static Uri contentUri(String artworkId) {
public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode) throws FileNotFoundException {
Context context = getContext();
String albumId = uri.getLastPathSegment();
Uri artworkUri;

if (albumId != null && albumId.startsWith("ir_")) {
String encodedUrl = albumId.substring("ir_".length());
String decodedUrl = new String(Base64.decode(encodedUrl, Base64.URL_SAFE | Base64.NO_WRAP));
artworkUri = Uri.parse(decodedUrl);
} else {
artworkUri = Uri.parse(CustomGlideRequest.createUrl(albumId, Preferences.getImageSize()));
}
Uri artworkUri = Uri.parse(CustomGlideRequest.createUrl(albumId, Preferences.getImageSize()));

try {
// use pipe to communicate between background thread and caller of openFile()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ class InternetRadioStation(
var streamUrl: String? = null,
@SerializedName("homePageUrl", alternate = ["homepageUrl"])
var homePageUrl: String? = null,
) : Parcelable
@SerializedName("coverArt")
var coverArtId: String? = null,
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,8 @@ public void onBindViewHolder(ViewHolder holder, int position) {
holder.item.internetRadioStationTitleTextView.setText(internetRadioStation.getName());
holder.item.internetRadioStationSubtitleTextView.setText(internetRadioStation.getStreamUrl());

String imageId = internetRadioStation.getHomePageUrl();
if (imageId == null || imageId.isEmpty()) {
imageId = internetRadioStation.getStreamUrl();
}

CustomGlideRequest.Builder
.from(holder.itemView.getContext(), imageId, CustomGlideRequest.ResourceType.Radio)
.from(holder.itemView.getContext(), internetRadioStation.getCoverArtId(), CustomGlideRequest.ResourceType.Radio)
.build()
.into(holder.item.internetRadioStationCoverImageView);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,13 @@ private void setMetadata(MediaMetadata mediaMetadata) {
: View.GONE);
}

String coverArtId = mediaMetadata.extras.getString("coverArtId");
CustomGlideRequest.ResourceType resourceType = Objects.equals(type, Constants.MEDIA_TYPE_RADIO)
? CustomGlideRequest.ResourceType.Radio
: CustomGlideRequest.ResourceType.Song;

CustomGlideRequest.Builder
.from(requireContext(), mediaMetadata.extras.getString("coverArtId"), CustomGlideRequest.ResourceType.Song)
.from(requireContext(), coverArtId, resourceType)
.build()
.into(bind.playerHeaderLayout.playerHeaderMediaCoverImage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,13 @@ public void onMediaMetadataChanged(@NonNull MediaMetadata mediaMetadata) {
}

private void setCover(MediaMetadata mediaMetadata) {
String type = mediaMetadata.extras != null ? mediaMetadata.extras.getString("type") : null;
CustomGlideRequest.ResourceType resourceType = Constants.MEDIA_TYPE_RADIO.equals(type)
? CustomGlideRequest.ResourceType.Radio
: CustomGlideRequest.ResourceType.Song;

CustomGlideRequest.Builder
.from(requireContext(), mediaMetadata.extras != null ? mediaMetadata.extras.getString("coverArtId") : null, CustomGlideRequest.ResourceType.Song)
.from(requireContext(), mediaMetadata.extras != null ? mediaMetadata.extras.getString("coverArtId") : null, resourceType)
.build()
.into(bind.nowPlayingSongCoverImageView);
}
Expand Down
29 changes: 12 additions & 17 deletions app/src/main/java/com/cappielloantonio/tempo/util/MappingUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.util.Base64;

import androidx.annotation.OptIn;
import androidx.lifecycle.LifecycleOwner;
Expand All @@ -27,7 +26,6 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.nio.charset.StandardCharsets;

@OptIn(markerClass = UnstableApi.class)
public class MappingUtil {
Expand Down Expand Up @@ -249,30 +247,27 @@ public static MediaItem mapDownload(Child media) {

public static MediaItem mapInternetRadioStation(InternetRadioStation internetRadioStation) {
Uri uri = Uri.parse(internetRadioStation.getStreamUrl());
Uri artworkUri = null;
String homePageUrl = internetRadioStation.getHomePageUrl();
String coverArtId = null;

if (homePageUrl != null && !homePageUrl.isEmpty() && MusicUtil.isImageUrl(homePageUrl)) {
String encodedUrl = Base64.encodeToString(homePageUrl.getBytes(StandardCharsets.UTF_8),
Base64.URL_SAFE | Base64.NO_WRAP);
coverArtId = "ir_" + encodedUrl;
artworkUri = AlbumArtContentProvider.contentUri(coverArtId);
}
String coverArtId = internetRadioStation.getCoverArtId();
Uri artworkUri = (coverArtId != null && !coverArtId.isEmpty())
? AlbumArtContentProvider.contentUri(coverArtId)
: null;

// `MediaItem.setMediaId()` requires a non-null id; different Subsonic servers may return null here.
String radioId = internetRadioStation.getId();
if (radioId == null || radioId.isEmpty()) radioId = internetRadioStation.getStreamUrl();
if (radioId == null || radioId.isEmpty()) radioId = internetRadioStation.getName();
if (radioId == null) radioId = "radio";

Bundle bundle = new Bundle();
bundle.putString("id", internetRadioStation.getId());
bundle.putString("id", radioId);
bundle.putString("title", internetRadioStation.getName());
bundle.putString("stationName", internetRadioStation.getName());
bundle.putString("uri", uri.toString());
bundle.putString("type", Constants.MEDIA_TYPE_RADIO);
bundle.putString("coverArtId", coverArtId);
if (homePageUrl != null) {
bundle.putString("homepageUrl", homePageUrl);
}

return new MediaItem.Builder()
.setMediaId(internetRadioStation.getId())
.setMediaId(radioId)
.setMediaMetadata(
new MediaMetadata.Builder()
.setTitle(internetRadioStation.getName())
Expand Down