mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-10 15:11:58 +01:00
choose the stream bitrate and format from settings
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package com.subtracks.data.prefs
|
||||
|
||||
import androidx.datastore.core.DataStore
|
||||
import androidx.datastore.preferences.core.Preferences
|
||||
import androidx.datastore.preferences.core.emptyPreferences
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
|
||||
fun fakeUserPreferences(): UserPreferences =
|
||||
UserPreferences(
|
||||
object : DataStore<Preferences> {
|
||||
private val state = MutableStateFlow(emptyPreferences())
|
||||
|
||||
override val data: Flow<Preferences> = state
|
||||
|
||||
override suspend fun updateData(transform: suspend (Preferences) -> Preferences): Preferences =
|
||||
transform(state.value).also { state.value = it }
|
||||
},
|
||||
)
|
||||
@@ -6,6 +6,7 @@ import androidx.sqlite.driver.bundled.BundledSQLiteDriver
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.subtracks.data.db.SubtracksDatabase
|
||||
import com.subtracks.data.prefs.fakeUserPreferences
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import okhttp3.OkHttpClient
|
||||
@@ -28,7 +29,7 @@ class SourceRepositoryTest {
|
||||
.inMemoryDatabaseBuilder(context, SubtracksDatabase::class.java)
|
||||
.setDriver(BundledSQLiteDriver())
|
||||
.build()
|
||||
repository = SourceRepository(db, OkHttpClient())
|
||||
repository = SourceRepository(db, OkHttpClient(), fakeUserPreferences())
|
||||
}
|
||||
|
||||
@After
|
||||
|
||||
@@ -8,6 +8,8 @@ import okhttp3.mockwebserver.MockWebServer
|
||||
import okhttp3.mockwebserver.RecordedRequest
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
||||
@@ -54,6 +56,31 @@ class SubsonicSourceTest {
|
||||
assertEquals(listOf("s1", "s2"), source.getSongs().map { it.id })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun streamUriRequestsTranscodingWhenABitrateIsSet() {
|
||||
val uri = SubsonicSource(1, client(), maxBitrate = 128).streamUri("s1").toString()
|
||||
|
||||
assertTrue(uri, uri.contains("maxBitRate=128"))
|
||||
assertTrue(uri, uri.contains("estimateContentLength=true"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun streamUriLeavesTheOriginalStreamAloneByDefault() {
|
||||
val uri = SubsonicSource(1, client()).streamUri("s1").toString()
|
||||
|
||||
assertFalse(uri, uri.contains("maxBitRate"))
|
||||
assertFalse(uri, uri.contains("format="))
|
||||
assertFalse(uri, uri.contains("estimateContentLength"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun streamUriRequestsAPreferredFormat() {
|
||||
val uri = SubsonicSource(1, client(), streamFormat = "opus").streamUri("s1").toString()
|
||||
|
||||
assertTrue(uri, uri.contains("format=opus"))
|
||||
assertTrue(uri, uri.contains("estimateContentLength=true"))
|
||||
}
|
||||
|
||||
private fun client() =
|
||||
SubsonicClient(
|
||||
baseUrl = server.url("/"),
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.subtracks.data.model.QueueEntry
|
||||
import com.subtracks.data.model.QueueKind
|
||||
import com.subtracks.data.model.Song
|
||||
import com.subtracks.data.model.Source
|
||||
import com.subtracks.data.prefs.fakeUserPreferences
|
||||
import com.subtracks.data.repo.QueueRepository
|
||||
import com.subtracks.data.repo.SourceRepository
|
||||
import kotlinx.coroutines.asCoroutineDispatcher
|
||||
@@ -42,7 +43,7 @@ class PlaybackControllerTest {
|
||||
.inMemoryDatabaseBuilder(context, SubtracksDatabase::class.java)
|
||||
.setDriver(BundledSQLiteDriver())
|
||||
.build()
|
||||
sources = SourceRepository(db, OkHttpClient())
|
||||
sources = SourceRepository(db, OkHttpClient(), fakeUserPreferences())
|
||||
queues = QueueRepository(db)
|
||||
handle = FakePlayerHandle()
|
||||
controller = PlaybackController(sources, queues, FakePlayerConnection(handle), dispatcher = dispatcher)
|
||||
@@ -61,7 +62,7 @@ class PlaybackControllerTest {
|
||||
seedAlbum(60, sourceId = 1)
|
||||
|
||||
controller.playAlbum(1, "al1", 30)
|
||||
await { handle.items.isNotEmpty() }
|
||||
await { handle.operations.contains("play") }
|
||||
|
||||
assertEquals(51, handle.itemCount)
|
||||
assertEquals(25, handle.currentIndex)
|
||||
|
||||
@@ -153,8 +153,12 @@ class AppScreenshotTest {
|
||||
SettingsScreen(
|
||||
sources = Fixtures.sources,
|
||||
activeSourceId = 1,
|
||||
maxBitrate = 0,
|
||||
streamFormat = null,
|
||||
onSelectSource = {},
|
||||
onDeleteSource = {},
|
||||
onMaxBitrateChange = {},
|
||||
onStreamFormatChange = {},
|
||||
onAddServer = {},
|
||||
onBack = {},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user