mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 18:03:33 +00:00
Preparation to music streaming
This commit is contained in:
parent
f837bb14e2
commit
a28ad27288
23 changed files with 615 additions and 279 deletions
|
|
@ -0,0 +1,54 @@
|
|||
package com.cappielloantonio.play.util;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.model.DirectPlayCodec;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
|
||||
import org.jellyfin.apiclient.interaction.ApiClient;
|
||||
|
||||
public class MusicUtil {
|
||||
public static String getSongFileUri(Song song) {
|
||||
ApiClient apiClient = App.getApiClientInstance(App.getInstance());
|
||||
PreferenceUtil preferenceUtil = PreferenceUtil.getInstance(App.getInstance());
|
||||
|
||||
StringBuilder builder = new StringBuilder(256);
|
||||
builder.append(apiClient.getApiUrl());
|
||||
builder.append("/Audio/");
|
||||
builder.append(song.getId());
|
||||
builder.append("/universal");
|
||||
builder.append("?UserId=").append(apiClient.getCurrentUserId());
|
||||
builder.append("&DeviceId=").append(apiClient.getDeviceId());
|
||||
|
||||
// web client maximum is 12444445 and 320kbps is 320000
|
||||
builder.append("&MaxStreamingBitrate=").append(preferenceUtil.getMaximumBitrate());
|
||||
|
||||
boolean containerAdded = false;
|
||||
for (DirectPlayCodec directPlayCodec : preferenceUtil.getDirectPlayCodecs()) {
|
||||
if (directPlayCodec.selected) {
|
||||
if (!containerAdded) {
|
||||
builder.append("&Container=");
|
||||
containerAdded = true;
|
||||
}
|
||||
|
||||
builder.append(directPlayCodec.codec.value).append(',');
|
||||
}
|
||||
}
|
||||
|
||||
if (containerAdded) {
|
||||
// remove last comma
|
||||
builder.deleteCharAt(builder.length() - 1);
|
||||
}
|
||||
|
||||
builder.append("&TranscodingContainer=ts");
|
||||
builder.append("&TranscodingProtocol=hls");
|
||||
|
||||
// preferred codec when transcoding
|
||||
builder.append("&AudioCodec=").append(preferenceUtil.getTranscodeCodec());
|
||||
builder.append("&api_key=").append(apiClient.getAccessToken());
|
||||
|
||||
Log.i(MusicUtil.class.getName(), "playing audio: " + builder);
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,12 @@ import android.content.SharedPreferences;
|
|||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.cappielloantonio.play.helper.ThemeHelper;
|
||||
import com.cappielloantonio.play.model.DirectPlayCodec;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class PreferenceUtil {
|
||||
public static final String SERVER = "server";
|
||||
|
|
@ -19,6 +25,10 @@ public class PreferenceUtil {
|
|||
public static final String HOST_URL = "host";
|
||||
public static final String IMAGE_CACHE_SIZE = "image_cache_size";
|
||||
|
||||
public static final String TRANSCODE_CODEC = "transcode_codec";
|
||||
public static final String DIRECT_PLAY_CODECS = "direct_play_codecs";
|
||||
public static final String MAXIMUM_BITRATE = "maximum_bitrate";
|
||||
|
||||
private static PreferenceUtil sInstance;
|
||||
|
||||
private final SharedPreferences mPreferences;
|
||||
|
|
@ -104,4 +114,46 @@ public class PreferenceUtil {
|
|||
public final int getImageCacheSize() {
|
||||
return Integer.parseInt(mPreferences.getString(IMAGE_CACHE_SIZE, "400000000"));
|
||||
}
|
||||
|
||||
public final String getTranscodeCodec() {
|
||||
return mPreferences.getString(TRANSCODE_CODEC, "aac");
|
||||
}
|
||||
|
||||
public final String getMaximumBitrate() {
|
||||
return mPreferences.getString(MAXIMUM_BITRATE, "10000000");
|
||||
}
|
||||
|
||||
public List<DirectPlayCodec> getDirectPlayCodecs() {
|
||||
DirectPlayCodec.Codec[] codecs = DirectPlayCodec.Codec.values();
|
||||
|
||||
Set<String> selectedCodecNames = new HashSet<>();
|
||||
for (DirectPlayCodec.Codec codec : codecs) {
|
||||
// this will be the default value
|
||||
selectedCodecNames.add(codec.name());
|
||||
}
|
||||
|
||||
selectedCodecNames = mPreferences.getStringSet(DIRECT_PLAY_CODECS, selectedCodecNames);
|
||||
|
||||
ArrayList<DirectPlayCodec> directPlayCodecs = new ArrayList<>();
|
||||
for (DirectPlayCodec.Codec codec : codecs) {
|
||||
String name = codec.name();
|
||||
boolean selected = selectedCodecNames.contains(name);
|
||||
directPlayCodecs.add(new DirectPlayCodec(codec, selected));
|
||||
}
|
||||
|
||||
return directPlayCodecs;
|
||||
}
|
||||
|
||||
public void setDirectPlayCodecs(List<DirectPlayCodec> directPlayCodecs) {
|
||||
Set<String> codecNames = new HashSet<>();
|
||||
for (DirectPlayCodec directPlayCodec : directPlayCodecs) {
|
||||
if (directPlayCodec.selected) {
|
||||
codecNames.add(directPlayCodec.codec.toString());
|
||||
}
|
||||
}
|
||||
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putStringSet(DIRECT_PLAY_CODECS, codecNames);
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
|
|
@ -8,14 +8,14 @@ import java.util.List;
|
|||
|
||||
public class QueueUtil {
|
||||
public static Queue getQueueElementFromSong(Song song) {
|
||||
return new Queue(song.getId());
|
||||
return new Queue(song.getId(), 0);
|
||||
}
|
||||
|
||||
public static List<Queue> getQueueElementsFromSongs(List<Song> songs) {
|
||||
List<Queue> queue = new ArrayList<>();
|
||||
|
||||
for(Song song: songs) {
|
||||
queue.add(new Queue(song.getId()));
|
||||
queue.add(new Queue(song.getId(), 0));
|
||||
}
|
||||
|
||||
return queue;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue