From 7d33770fd6e8a661a76ea1dd20b2f4d04224d699 Mon Sep 17 00:00:00 2001 From: tzugen Date: Tue, 12 Apr 2022 17:12:17 +0200 Subject: [PATCH] Add some more logging calls --- .../ultrasonic/playback/APIDataSource.kt | 24 +++++++++---------- .../ultrasonic/playback/CachedDataSource.kt | 10 ++++++++ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/playback/APIDataSource.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/playback/APIDataSource.kt index 75789ae7..f5b652ad 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/playback/APIDataSource.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/playback/APIDataSource.kt @@ -132,6 +132,13 @@ open class APIDataSource private constructor( @Suppress("LongMethod", "NestedBlockDepth") @Throws(HttpDataSourceException::class) override fun open(dataSpec: DataSpec): Long { + Timber.i( + "APIDatasource: Open: %s %s %s", + dataSpec.uri, + dataSpec.position, + dataSpec.toString() + ) + this.dataSpec = dataSpec bytesRead = 0 bytesToRead = 0 @@ -140,22 +147,15 @@ open class APIDataSource private constructor( val components = dataSpec.uri.toString().split('|') val id = components[0] val bitrate = components[1].toInt() - - Timber.i("DATASOURCE: %s", "Start") - // FIXME - // WRONG API CLIENT val request = subsonicAPIClient.api.stream(id, bitrate, offset = 0) val response: retrofit2.Response? val streamResponse: StreamResponse - Timber.i("DATASOURCE: %s", "Start2") + try { this.response = request.execute() - Timber.i("DATASOURCE: %s", "Start3") response = this.response streamResponse = response!!.toStreamResponse() - Timber.i("DATASOURCE: %s", "Start4") responseByteStream = streamResponse.stream - Timber.i("DATASOURCE: %s", "Start5") } catch (e: IOException) { throw HttpDataSourceException.createForIOException( e, dataSpec, HttpDataSourceException.TYPE_OPEN @@ -193,8 +193,6 @@ open class APIDataSource private constructor( ) } - Timber.i("DATASOURCE: %s", "Start6") - // If we requested a range starting from a non-zero position and received a 200 rather than a // 206, then the server does not support partial requests. We'll need to manually skip to the // requested position. @@ -216,13 +214,13 @@ open class APIDataSource private constructor( closeConnectionQuietly() throw e } - Timber.i("DATASOURCE: %s", "Start7") return bytesToRead } @Throws(HttpDataSourceException::class) override fun read(buffer: ByteArray, offset: Int, length: Int): Int { + Timber.i("APIDatasource: Read: %s %s %s", buffer, offset, length) return try { readInternal(buffer, offset, length) } catch (e: IOException) { @@ -233,6 +231,7 @@ open class APIDataSource private constructor( } override fun close() { + Timber.i("APIDatasource: Close") if (openedNetwork) { openedNetwork = false transferEnded() @@ -322,8 +321,7 @@ open class APIDataSource private constructor( return C.RESULT_END_OF_INPUT } bytesRead += read.toLong() - // TODO - // bytesTransferred(read) + bytesTransferred(read) return read } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/playback/CachedDataSource.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/playback/CachedDataSource.kt index e79e66dd..e200b5f4 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/playback/CachedDataSource.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/playback/CachedDataSource.kt @@ -22,6 +22,7 @@ import java.io.InputStream import org.moire.ultrasonic.util.AbstractFile import org.moire.ultrasonic.util.FileUtil import org.moire.ultrasonic.util.Storage +import timber.log.Timber @androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class) class CachedDataSource( @@ -92,6 +93,13 @@ class CachedDataSource( private var cacheFile: AbstractFile? = null override fun open(dataSpec: DataSpec): Long { + Timber.i( + "CachedDatasource: Open: %s %s %s", + dataSpec.uri, + dataSpec.position, + dataSpec.toString() + ) + this.dataSpec = dataSpec bytesRead = 0 bytesToRead = 0 @@ -112,6 +120,7 @@ class CachedDataSource( } override fun read(buffer: ByteArray, offset: Int, length: Int): Int { + Timber.i("CachedDatasource: Read: %s %s %s", buffer, offset, length) return if (cachePath != null) { try { readInternal(buffer, offset, length) @@ -156,6 +165,7 @@ class CachedDataSource( } override fun close() { + Timber.i("CachedDatasource: close") if (openedFile) { openedFile = false responseByteStream?.close()