mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 18:03:33 +00:00
Add audio transcode format option and bitrate
This commit is contained in:
parent
10df98306c
commit
bb9b2d95b5
8 changed files with 175 additions and 36 deletions
|
|
@ -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<Song> 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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<String, String> 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<String, String> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue