diff --git a/app/src/main/java/com/cappielloantonio/play/service/DownloadTracker.java b/app/src/main/java/com/cappielloantonio/play/service/DownloadTracker.java index 77e93c37..1a896f1a 100644 --- a/app/src/main/java/com/cappielloantonio/play/service/DownloadTracker.java +++ b/app/src/main/java/com/cappielloantonio/play/service/DownloadTracker.java @@ -63,14 +63,14 @@ public class DownloadTracker { } public boolean isDownloaded(Song song) { - MediaItem mediaItem = MusicUtil.getMediaItemFromSong(song); + MediaItem mediaItem = MusicUtil.getSongDownloadItem(song); @Nullable Download download = downloads.get(checkNotNull(mediaItem.playbackProperties).uri); return download != null && download.state != Download.STATE_FAILED; } public boolean isDownloaded(List songs) { for (Song song : songs) { - MediaItem mediaItem = MusicUtil.getMediaItemFromSong(song); + MediaItem mediaItem = MusicUtil.getSongDownloadItem(song); @Nullable Download download = downloads.get(checkNotNull(mediaItem.playbackProperties).uri); if (download != null && download.state != Download.STATE_FAILED) { @@ -95,7 +95,7 @@ public class DownloadTracker { continue; } - MediaItem mediaItem = MusicUtil.getMediaItemFromSong(song); + MediaItem mediaItem = MusicUtil.getSongDownloadItem(song); DownloadService.sendAddDownload(context, DownloaderService.class, getDownloadRequest(song.getId(), checkNotNull(mediaItem.playbackProperties).uri), false); downloadRepository.insert(MappingUtil.mapToDownload(song, playlistId, playlistName)); } @@ -105,7 +105,7 @@ public class DownloadTracker { DownloadRepository downloadRepository = new DownloadRepository(App.getInstance()); for (Song song : songs) { - MediaItem mediaItem = MusicUtil.getMediaItemFromSong(song); + MediaItem mediaItem = MusicUtil.getSongDownloadItem(song); @Nullable Download download = downloads.get(checkNotNull(mediaItem.playbackProperties).uri); diff --git a/app/src/main/java/com/cappielloantonio/play/service/MultiPlayer.java b/app/src/main/java/com/cappielloantonio/play/service/MultiPlayer.java index 4873d4f0..9222b254 100644 --- a/app/src/main/java/com/cappielloantonio/play/service/MultiPlayer.java +++ b/app/src/main/java/com/cappielloantonio/play/service/MultiPlayer.java @@ -130,7 +130,7 @@ public class MultiPlayer implements Playback { @Override public void setDataSource(Song song) { - String uri = MusicUtil.getSongFileUri(song); + String uri = MusicUtil.getSongStreamUri(context, song); MediaItem mediaItem = exoPlayer.getCurrentMediaItem(); if (mediaItem != null && mediaItem.playbackProperties != null && mediaItem.playbackProperties.uri.toString().equals(uri)) { @@ -138,7 +138,7 @@ public class MultiPlayer implements Playback { } exoPlayer.clearMediaItems(); - appendDataSource(MusicUtil.getSongFileUri(song)); + appendDataSource(MusicUtil.getSongStreamUri(context, song)); exoPlayer.seekTo(0, 0); } @@ -149,7 +149,7 @@ public class MultiPlayer implements Playback { exoPlayer.removeMediaItem(1); } - appendDataSource(MusicUtil.getSongFileUri(song)); + appendDataSource(MusicUtil.getSongStreamUri(context, song)); } private void appendDataSource(String path) { diff --git a/app/src/main/java/com/cappielloantonio/play/ui/fragment/dialog/ServerSignupDialog.java b/app/src/main/java/com/cappielloantonio/play/ui/fragment/dialog/ServerSignupDialog.java index 08471baf..11589d0b 100644 --- a/app/src/main/java/com/cappielloantonio/play/ui/fragment/dialog/ServerSignupDialog.java +++ b/app/src/main/java/com/cappielloantonio/play/ui/fragment/dialog/ServerSignupDialog.java @@ -81,14 +81,16 @@ public class ServerSignupDialog extends DialogFragment { } private void setServerInfo() { - loginViewModel.setServerToEdit(requireArguments().getParcelable("server_object")); + if (getArguments() != null) { + loginViewModel.setServerToEdit(requireArguments().getParcelable("server_object")); - if (loginViewModel.getServerToEdit() != null) { - bind.serverNameTextView.setText(loginViewModel.getServerToEdit().getServerName()); - bind.usernameTextView.setText(loginViewModel.getServerToEdit().getUsername()); - bind.passwordTextView.setText(""); - bind.serverTextView.setText(loginViewModel.getServerToEdit().getAddress()); - bind.directAccessCheckbox.setChecked(false); + if (loginViewModel.getServerToEdit() != null) { + bind.serverNameTextView.setText(loginViewModel.getServerToEdit().getServerName()); + bind.usernameTextView.setText(loginViewModel.getServerToEdit().getUsername()); + bind.passwordTextView.setText(""); + bind.serverTextView.setText(loginViewModel.getServerToEdit().getAddress()); + bind.directAccessCheckbox.setChecked(false); + } } } diff --git a/app/src/main/java/com/cappielloantonio/play/util/MusicUtil.java b/app/src/main/java/com/cappielloantonio/play/util/MusicUtil.java index 279e07c6..0c0fcadd 100644 --- a/app/src/main/java/com/cappielloantonio/play/util/MusicUtil.java +++ b/app/src/main/java/com/cappielloantonio/play/util/MusicUtil.java @@ -1,6 +1,8 @@ package com.cappielloantonio.play.util; +import android.content.Context; import android.text.Html; +import android.util.Log; import com.cappielloantonio.play.App; import com.cappielloantonio.play.R; @@ -17,18 +19,34 @@ import java.util.regex.Pattern; public class MusicUtil { private static final String TAG = "MusicUtil"; - public static String getSongFileUri(Song song) { - String url = App.getSubsonicClientInstance(App.getInstance(), false).getUrl(); - + public static String getSongStreamUri(Context context, Song song) { Map params = App.getSubsonicClientInstance(App.getInstance(), false).getParams(); - return url + "stream" + + return App.getSubsonicClientInstance(App.getInstance(), false).getUrl() + + "stream" + + "?u=" + params.get("u") + + "&s=" + params.get("s") + + "&t=" + params.get("t") + + "&v=" + params.get("v") + + "&c=" + params.get("c") + + "&id=" + song.getId() + + "&maxBitRate=" + PreferenceUtil.getInstance(context).getMaxBitrateWifi() + + "&format=" + PreferenceUtil.getInstance(context).getAudioTranscodeFormat(); + } + + public static MediaItem getSongDownloadItem(Song song) { + Map params = App.getSubsonicClientInstance(App.getInstance(), false).getParams(); + + String uri = App.getSubsonicClientInstance(App.getInstance(), false).getUrl() + + "stream" + "?u=" + params.get("u") + "&s=" + params.get("s") + "&t=" + params.get("t") + "&v=" + params.get("v") + "&c=" + params.get("c") + "&id=" + song.getId(); + + return MediaItem.fromUri(uri); } public static String getReadableDurationString(long duration, boolean millis) { @@ -110,9 +128,4 @@ public class MusicUtil { return R.drawable.default_album_art; } } - - public static MediaItem getMediaItemFromSong(Song song) { - String uri = MusicUtil.getSongFileUri(song); - return MediaItem.fromUri(uri); - } } diff --git a/app/src/main/java/com/cappielloantonio/play/util/PreferenceUtil.java b/app/src/main/java/com/cappielloantonio/play/util/PreferenceUtil.java index 643e53df..1bce1882 100644 --- a/app/src/main/java/com/cappielloantonio/play/util/PreferenceUtil.java +++ b/app/src/main/java/com/cappielloantonio/play/util/PreferenceUtil.java @@ -21,6 +21,10 @@ public class PreferenceUtil { public static final String IMAGE_CACHE_SIZE = "image_cache_size"; public static final String IMAGE_SIZE = "image_size"; public static final String MEDIA_CACHE_SIZE = "media_cache_size"; + public static final String MAX_BITRATE_WIFI = "max_bitrate_wifi"; + public static final String MAX_BITRATE_MOBILE = "max_bitrate_mobile"; + public static final String AUDIO_TRANSCODE_FORMAT = "audio_transcode_format"; + public static final String WIFI_ONLY = "wifi_only"; private static PreferenceUtil sInstance; private final SharedPreferences mPreferences; @@ -42,7 +46,7 @@ public class PreferenceUtil { } public String getServer() { - return mPreferences.getString(SERVER, "https://jellyfin.org"); + return mPreferences.getString(SERVER, ""); } public void setServer(String server) { @@ -132,4 +136,20 @@ public class PreferenceUtil { public final int getImageSize() { return Integer.parseInt(mPreferences.getString(IMAGE_SIZE, "-1")); } + + public final String getMaxBitrateWifi() { + return mPreferences.getString(MAX_BITRATE_WIFI, "0"); + } + + public final String getMaxBitrateMobile() { + return mPreferences.getString(MAX_BITRATE_MOBILE, "0"); + } + + public final String getAudioTranscodeFormat() { + return mPreferences.getString(AUDIO_TRANSCODE_FORMAT, "raw"); + } + + public final boolean isWifiOnly() { + return mPreferences.getBoolean(WIFI_ONLY, false); + } } \ No newline at end of file diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 3d995264..3ce1d8b2 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -1,13 +1,10 @@ - - - + Light Dark System default - - + light dark default @@ -20,7 +17,6 @@ 400MB 200MB - 4000000000 2000000000 @@ -36,7 +32,6 @@ 400MB 200MB - 4000000000 2000000000 @@ -50,10 +45,82 @@ Medium Low - -1 500 300 + + + Original + 32 + 48 + 64 + 80 + 96 + 112 + 128 + 160 + 192 + 256 + 320 + + + 0 + 32 + 48 + 64 + 80 + 96 + 112 + 128 + 160 + 192 + 256 + 320 + + + + Original + 32 + 48 + 64 + 80 + 96 + 112 + 128 + 160 + 192 + 256 + 320 + + + 0 + 32 + 48 + 64 + 80 + 96 + 112 + 128 + 160 + 192 + 256 + 320 + + + + Original + Opus + AAC + Mp3 + Flac + + + raw + opus + aac + mp3 + flac + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 984e3082..f8620427 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -141,16 +141,21 @@ Add server Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. About + Transcode format Covers cache https://github.com/CappielloAntonio/play-for-subsonic Follow the development Github Cover size + Bitrate in WiFi + Bitrate in mobile Media cache Choose theme General 1.0 Version + WiFi only + Summary WiFi only Add to playlist Add to queue Download diff --git a/app/src/main/res/xml/global_preferences.xml b/app/src/main/res/xml/global_preferences.xml index 912a2998..33eaf1f1 100644 --- a/app/src/main/res/xml/global_preferences.xml +++ b/app/src/main/res/xml/global_preferences.xml @@ -31,12 +31,45 @@ + + + + + + + + -