Add some more logging calls

This commit is contained in:
tzugen 2022-04-12 17:12:17 +02:00
parent 728afad00c
commit 7d33770fd6
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
2 changed files with 21 additions and 13 deletions

View File

@ -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<ResponseBody>?
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
}

View File

@ -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()