mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-05-16 15:26:35 +03:00
Fix insertAfterCurrent, Fix getUri
This commit is contained in:
parent
dd65a12b53
commit
46fb7664c3
@ -138,6 +138,8 @@ open class APIDataSource private constructor(
|
|||||||
val bitrate = components[1].toInt()
|
val bitrate = components[1].toInt()
|
||||||
|
|
||||||
Timber.i("DATASOURCE: %s", "Start")
|
Timber.i("DATASOURCE: %s", "Start")
|
||||||
|
// FIXME
|
||||||
|
// WRONG API CLIENT
|
||||||
val request = subsonicAPIClient.api.stream(id, bitrate, offset = 0)
|
val request = subsonicAPIClient.api.stream(id, bitrate, offset = 0)
|
||||||
val response: retrofit2.Response<ResponseBody>?
|
val response: retrofit2.Response<ResponseBody>?
|
||||||
val streamResponse: StreamResponse
|
val streamResponse: StreamResponse
|
||||||
|
@ -107,7 +107,6 @@ class AutoMediaBrowserCallback(var player: Player) :
|
|||||||
private val useId3Tags get() = Settings.shouldUseId3Tags
|
private val useId3Tags get() = Settings.shouldUseId3Tags
|
||||||
private val musicFolderId get() = activeServerProvider.getActiveServer().musicFolderId
|
private val musicFolderId get() = activeServerProvider.getActiveServer().musicFolderId
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a {@link MediaBrowser} requests the root {@link MediaItem} by {@link
|
* Called when a {@link MediaBrowser} requests the root {@link MediaItem} by {@link
|
||||||
* MediaBrowser#getLibraryRoot(LibraryParams)}.
|
* MediaBrowser#getLibraryRoot(LibraryParams)}.
|
||||||
@ -162,7 +161,9 @@ class AutoMediaBrowserCallback(var player: Player) :
|
|||||||
): ListenableFuture<LibraryResult<MediaItem>> {
|
): ListenableFuture<LibraryResult<MediaItem>> {
|
||||||
playFromMediaId(mediaId)
|
playFromMediaId(mediaId)
|
||||||
|
|
||||||
// TODO: Later
|
// FIXME:
|
||||||
|
// Create LRU Cache of MediaItems, fill it in the other calls
|
||||||
|
// and retrieve it here.
|
||||||
return Futures.immediateFuture(
|
return Futures.immediateFuture(
|
||||||
LibraryResult.ofError(LibraryResult.RESULT_ERROR_BAD_VALUE)
|
LibraryResult.ofError(LibraryResult.RESULT_ERROR_BAD_VALUE)
|
||||||
)
|
)
|
||||||
@ -215,7 +216,6 @@ class AutoMediaBrowserCallback(var player: Player) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Suppress("ReturnCount", "ComplexMethod")
|
@Suppress("ReturnCount", "ComplexMethod")
|
||||||
fun onLoadChildren(
|
fun onLoadChildren(
|
||||||
parentId: String,
|
parentId: String,
|
||||||
@ -300,7 +300,6 @@ class AutoMediaBrowserCallback(var player: Player) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Suppress("MagicNumber", "ComplexMethod")
|
@Suppress("MagicNumber", "ComplexMethod")
|
||||||
private fun playFromMediaId(mediaId: String?) {
|
private fun playFromMediaId(mediaId: String?) {
|
||||||
Timber.d(
|
Timber.d(
|
||||||
@ -1083,7 +1082,6 @@ class AutoMediaBrowserCallback(var player: Player) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun buildMediaItemFromTrack(
|
private fun buildMediaItemFromTrack(
|
||||||
track: Track,
|
track: Track,
|
||||||
mediaId: String,
|
mediaId: String,
|
||||||
@ -1129,5 +1127,4 @@ class AutoMediaBrowserCallback(var player: Player) :
|
|||||||
.setUri(sourceUri)
|
.setUri(sourceUri)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
@ -147,8 +147,12 @@ class CachedDataSource(
|
|||||||
return read
|
return read
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This method is called by StatsDataSource to verify that the loading succeeded,
|
||||||
|
* so its important that we return the correct value here..
|
||||||
|
*/
|
||||||
override fun getUri(): Uri? {
|
override fun getUri(): Uri? {
|
||||||
return cachePath?.toUri()
|
return cachePath?.toUri() ?: upstreamDataSource.uri
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun close() {
|
override fun close() {
|
||||||
@ -174,6 +178,7 @@ class CachedDataSource(
|
|||||||
if (!found) return -1
|
if (!found) return -1
|
||||||
|
|
||||||
cachePath = filePath
|
cachePath = filePath
|
||||||
|
openedFile = true
|
||||||
|
|
||||||
cacheFile = Storage.getFromPath(filePath)!!
|
cacheFile = Storage.getFromPath(filePath)!!
|
||||||
responseByteStream = cacheFile!!.getFileInputStream()
|
responseByteStream = cacheFile!!.getFileInputStream()
|
||||||
|
@ -399,11 +399,11 @@ class Downloader(
|
|||||||
val fileLength = Storage.getFromPath(downloadFile.partialFile)?.length ?: 0
|
val fileLength = Storage.getFromPath(downloadFile.partialFile)?.length ?: 0
|
||||||
|
|
||||||
needsDownloading = (
|
needsDownloading = (
|
||||||
downloadFile.desiredBitRate == 0 ||
|
downloadFile.desiredBitRate == 0 ||
|
||||||
duration == null ||
|
duration == null ||
|
||||||
duration == 0 ||
|
duration == 0 ||
|
||||||
fileLength == 0L
|
fileLength == 0L
|
||||||
)
|
)
|
||||||
|
|
||||||
if (needsDownloading) {
|
if (needsDownloading) {
|
||||||
// Attempt partial HTTP GET, appending to the file if it exists.
|
// Attempt partial HTTP GET, appending to the file if it exists.
|
||||||
|
@ -366,7 +366,7 @@ class MediaPlayerController(
|
|||||||
when (insertionMode) {
|
when (insertionMode) {
|
||||||
InsertionMode.CLEAR -> clear()
|
InsertionMode.CLEAR -> clear()
|
||||||
InsertionMode.APPEND -> insertAt = mediaItemCount
|
InsertionMode.APPEND -> insertAt = mediaItemCount
|
||||||
InsertionMode.AFTER_CURRENT -> insertAt = currentMediaItemIndex
|
InsertionMode.AFTER_CURRENT -> insertAt = currentMediaItemIndex + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
val mediaItems: List<MediaItem> = songs.map {
|
val mediaItems: List<MediaItem> = songs.map {
|
||||||
|
@ -109,10 +109,10 @@ class MediaPlayerLifecycleSupport : KoinComponent {
|
|||||||
|
|
||||||
val autoStart =
|
val autoStart =
|
||||||
keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE ||
|
keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE ||
|
||||||
keyCode == KeyEvent.KEYCODE_MEDIA_PLAY ||
|
keyCode == KeyEvent.KEYCODE_MEDIA_PLAY ||
|
||||||
keyCode == KeyEvent.KEYCODE_HEADSETHOOK ||
|
keyCode == KeyEvent.KEYCODE_HEADSETHOOK ||
|
||||||
keyCode == KeyEvent.KEYCODE_MEDIA_PREVIOUS ||
|
keyCode == KeyEvent.KEYCODE_MEDIA_PREVIOUS ||
|
||||||
keyCode == KeyEvent.KEYCODE_MEDIA_NEXT
|
keyCode == KeyEvent.KEYCODE_MEDIA_NEXT
|
||||||
|
|
||||||
// We can receive intents (e.g. MediaButton) when everything is stopped, so we need to start
|
// We can receive intents (e.g. MediaButton) when everything is stopped, so we need to start
|
||||||
onCreate(autoStart) {
|
onCreate(autoStart) {
|
||||||
@ -149,10 +149,10 @@ class MediaPlayerLifecycleSupport : KoinComponent {
|
|||||||
return
|
return
|
||||||
|
|
||||||
val autoStart = action == Constants.CMD_PLAY ||
|
val autoStart = action == Constants.CMD_PLAY ||
|
||||||
action == Constants.CMD_RESUME_OR_PLAY ||
|
action == Constants.CMD_RESUME_OR_PLAY ||
|
||||||
action == Constants.CMD_TOGGLEPAUSE ||
|
action == Constants.CMD_TOGGLEPAUSE ||
|
||||||
action == Constants.CMD_PREVIOUS ||
|
action == Constants.CMD_PREVIOUS ||
|
||||||
action == Constants.CMD_NEXT
|
action == Constants.CMD_NEXT
|
||||||
|
|
||||||
// We can receive intents when everything is stopped, so we need to start
|
// We can receive intents when everything is stopped, so we need to start
|
||||||
onCreate(autoStart) {
|
onCreate(autoStart) {
|
||||||
|
@ -39,8 +39,8 @@ class DownloadHandler(
|
|||||||
val onValid = Runnable {
|
val onValid = Runnable {
|
||||||
// TODO: The logic here is different than in the controller...
|
// TODO: The logic here is different than in the controller...
|
||||||
val insertionMode = when {
|
val insertionMode = when {
|
||||||
append -> MediaPlayerController.InsertionMode.APPEND
|
|
||||||
playNext -> MediaPlayerController.InsertionMode.AFTER_CURRENT
|
playNext -> MediaPlayerController.InsertionMode.AFTER_CURRENT
|
||||||
|
append -> MediaPlayerController.InsertionMode.APPEND
|
||||||
else -> MediaPlayerController.InsertionMode.CLEAR
|
else -> MediaPlayerController.InsertionMode.CLEAR
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,13 +33,6 @@ import android.view.Gravity
|
|||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.annotation.AnyRes
|
import androidx.annotation.AnyRes
|
||||||
import org.moire.ultrasonic.R
|
|
||||||
import org.moire.ultrasonic.app.UApp.Companion.applicationContext
|
|
||||||
import org.moire.ultrasonic.domain.Bookmark
|
|
||||||
import org.moire.ultrasonic.domain.MusicDirectory
|
|
||||||
import org.moire.ultrasonic.domain.SearchResult
|
|
||||||
import org.moire.ultrasonic.domain.Track
|
|
||||||
import timber.log.Timber
|
|
||||||
import java.io.Closeable
|
import java.io.Closeable
|
||||||
import java.io.UnsupportedEncodingException
|
import java.io.UnsupportedEncodingException
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
@ -49,6 +42,13 @@ import java.util.concurrent.TimeUnit
|
|||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
import org.moire.ultrasonic.R
|
||||||
|
import org.moire.ultrasonic.app.UApp.Companion.applicationContext
|
||||||
|
import org.moire.ultrasonic.domain.Bookmark
|
||||||
|
import org.moire.ultrasonic.domain.MusicDirectory
|
||||||
|
import org.moire.ultrasonic.domain.SearchResult
|
||||||
|
import org.moire.ultrasonic.domain.Track
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
private const val LINE_LENGTH = 60
|
private const val LINE_LENGTH = 60
|
||||||
private const val DEGRADE_PRECISION_AFTER = 10
|
private const val DEGRADE_PRECISION_AFTER = 10
|
||||||
@ -509,7 +509,7 @@ object Util {
|
|||||||
val hours = TimeUnit.MILLISECONDS.toHours(millis)
|
val hours = TimeUnit.MILLISECONDS.toHours(millis)
|
||||||
val minutes = TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(hours)
|
val minutes = TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(hours)
|
||||||
val seconds = TimeUnit.MILLISECONDS.toSeconds(millis) -
|
val seconds = TimeUnit.MILLISECONDS.toSeconds(millis) -
|
||||||
TimeUnit.MINUTES.toSeconds(hours * MINUTES_IN_HOUR + minutes)
|
TimeUnit.MINUTES.toSeconds(hours * MINUTES_IN_HOUR + minutes)
|
||||||
|
|
||||||
return when {
|
return when {
|
||||||
hours >= DEGRADE_PRECISION_AFTER -> {
|
hours >= DEGRADE_PRECISION_AFTER -> {
|
||||||
@ -603,9 +603,9 @@ object Util {
|
|||||||
fun getUriToDrawable(context: Context, @AnyRes drawableId: Int): Uri {
|
fun getUriToDrawable(context: Context, @AnyRes drawableId: Int): Uri {
|
||||||
return Uri.parse(
|
return Uri.parse(
|
||||||
ContentResolver.SCHEME_ANDROID_RESOURCE +
|
ContentResolver.SCHEME_ANDROID_RESOURCE +
|
||||||
"://" + context.resources.getResourcePackageName(drawableId) +
|
"://" + context.resources.getResourcePackageName(drawableId) +
|
||||||
'/' + context.resources.getResourceTypeName(drawableId) +
|
'/' + context.resources.getResourceTypeName(drawableId) +
|
||||||
'/' + context.resources.getResourceEntryName(drawableId)
|
'/' + context.resources.getResourceEntryName(drawableId)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -643,8 +643,8 @@ object Util {
|
|||||||
|
|
||||||
if (artistName != null) {
|
if (artistName != null) {
|
||||||
if (Settings.shouldDisplayBitrateWithArtist && (
|
if (Settings.shouldDisplayBitrateWithArtist && (
|
||||||
!bitRate.isNullOrBlank() || !fileFormat.isNullOrBlank()
|
!bitRate.isNullOrBlank() || !fileFormat.isNullOrBlank()
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
artist.append(artistName).append(" (").append(
|
artist.append(artistName).append(" (").append(
|
||||||
String.format(
|
String.format(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user