2020-12-08 11:12:44 +01:00
|
|
|
package com.cappielloantonio.play.util;
|
|
|
|
|
|
2021-08-01 19:08:40 +02:00
|
|
|
import android.text.Html;
|
|
|
|
|
|
2020-12-08 11:12:44 +01:00
|
|
|
import com.cappielloantonio.play.App;
|
2021-04-14 14:06:35 +02:00
|
|
|
import com.cappielloantonio.play.R;
|
|
|
|
|
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
2020-12-08 11:12:44 +01:00
|
|
|
import com.cappielloantonio.play.model.Song;
|
2021-04-26 19:17:42 +02:00
|
|
|
import com.google.android.exoplayer2.MediaItem;
|
2020-12-08 11:12:44 +01:00
|
|
|
|
2021-04-12 12:43:34 +02:00
|
|
|
import java.util.Locale;
|
2021-07-27 14:53:03 +02:00
|
|
|
import java.util.Map;
|
2021-04-12 12:43:34 +02:00
|
|
|
|
2020-12-08 11:12:44 +01:00
|
|
|
public class MusicUtil {
|
2021-07-27 14:53:03 +02:00
|
|
|
private static final String TAG = "MusicUtil";
|
2020-12-08 11:12:44 +01:00
|
|
|
|
2021-07-27 14:53:03 +02:00
|
|
|
public static String getSongFileUri(Song song) {
|
|
|
|
|
String url = App.getSubsonicClientInstance(App.getInstance(), false).getUrl();
|
2020-12-08 11:12:44 +01:00
|
|
|
|
2021-07-27 14:53:03 +02:00
|
|
|
Map<String, String> params = App.getSubsonicClientInstance(App.getInstance(), false).getParams();
|
2020-12-08 11:12:44 +01:00
|
|
|
|
2021-07-27 14:53:03 +02:00
|
|
|
return url + "stream" +
|
|
|
|
|
"?u=" + params.get("u") +
|
|
|
|
|
"&s=" + params.get("s") +
|
|
|
|
|
"&t=" + params.get("t") +
|
|
|
|
|
"&v=" + params.get("v") +
|
|
|
|
|
"&c=" + params.get("c") +
|
|
|
|
|
"&id=" + song.getId();
|
2020-12-08 11:12:44 +01:00
|
|
|
}
|
2021-04-12 12:43:34 +02:00
|
|
|
|
2021-07-28 18:53:42 +02:00
|
|
|
public static String getReadableDurationString(long duration, boolean millis) {
|
|
|
|
|
long minutes = 0;
|
|
|
|
|
long seconds = 0;
|
|
|
|
|
|
2021-07-30 17:34:15 +02:00
|
|
|
if (millis) {
|
2021-07-28 18:53:42 +02:00
|
|
|
minutes = (duration / 1000) / 60;
|
|
|
|
|
seconds = (duration / 1000) % 60;
|
2021-07-30 17:34:15 +02:00
|
|
|
} else {
|
2021-07-28 18:53:42 +02:00
|
|
|
minutes = duration / 60;
|
|
|
|
|
seconds = duration % 60;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-12 12:43:34 +02:00
|
|
|
if (minutes < 60) {
|
|
|
|
|
return String.format(Locale.getDefault(), "%01d:%02d", minutes, seconds);
|
|
|
|
|
} else {
|
|
|
|
|
long hours = minutes / 60;
|
|
|
|
|
minutes = minutes % 60;
|
|
|
|
|
return String.format(Locale.getDefault(), "%d:%02d:%02d", hours, minutes, seconds);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-14 14:06:35 +02:00
|
|
|
|
2021-08-01 19:08:40 +02:00
|
|
|
public static String getReadableInfo(String info) {
|
|
|
|
|
if (info != null) {
|
|
|
|
|
return Html.fromHtml(info, Html.FROM_HTML_MODE_COMPACT).toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 14:06:35 +02:00
|
|
|
public static int getDefaultPicPerCategory(String category) {
|
2021-04-27 11:01:02 +02:00
|
|
|
if (category.equals(CustomGlideRequest.SONG_PIC)) {
|
2021-04-14 14:06:35 +02:00
|
|
|
return R.drawable.default_album_art;
|
2021-04-27 11:01:02 +02:00
|
|
|
} else if (category.equals(CustomGlideRequest.ALBUM_PIC)) {
|
2021-04-14 14:06:35 +02:00
|
|
|
return R.drawable.default_album_art;
|
2021-04-27 11:01:02 +02:00
|
|
|
} else if (category.equals(CustomGlideRequest.ARTIST_PIC)) {
|
2021-04-14 14:06:35 +02:00
|
|
|
return R.drawable.default_album_art;
|
2021-04-27 11:01:02 +02:00
|
|
|
} else if (category.equals(CustomGlideRequest.PLAYLIST_PIC)) {
|
2021-04-14 14:06:35 +02:00
|
|
|
return R.drawable.default_album_art;
|
2021-04-27 11:01:02 +02:00
|
|
|
} else {
|
2021-04-14 14:06:35 +02:00
|
|
|
return R.drawable.default_album_art;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-20 12:36:58 +02:00
|
|
|
|
2021-04-26 19:17:42 +02:00
|
|
|
public static MediaItem getMediaItemFromSong(Song song) {
|
|
|
|
|
String uri = MusicUtil.getSongFileUri(song);
|
|
|
|
|
MediaItem mediaItem = MediaItem.fromUri(uri);
|
|
|
|
|
return mediaItem;
|
|
|
|
|
}
|
2020-12-08 11:12:44 +01:00
|
|
|
}
|