Post capabilities when creating Home View Model

This commit is contained in:
Jarne Demeulemeester 2021-07-19 16:03:54 +02:00
parent 21067bd7d0
commit f7ef7736ac
No known key found for this signature in database
GPG key ID: 60884A0C1EBA43E5
4 changed files with 30 additions and 17 deletions

View file

@ -26,6 +26,8 @@ interface JellyfinRepository {
suspend fun getStreamUrl(itemId: UUID, mediaSourceId: String): String suspend fun getStreamUrl(itemId: UUID, mediaSourceId: String): String
suspend fun postCapabilities()
suspend fun postPlaybackStart(itemId: UUID) suspend fun postPlaybackStart(itemId: UUID)
suspend fun postPlaybackStop(itemId: UUID, positionTicks: Long) suspend fun postPlaybackStop(itemId: UUID, positionTicks: Long)

View file

@ -145,6 +145,30 @@ class JellyfinRepositoryImpl(private val jellyfinApi: JellyfinApi) : JellyfinRep
return streamUrl return streamUrl
} }
override suspend fun postCapabilities() {
Timber.d("Sending capabilities")
withContext(Dispatchers.IO) {
jellyfinApi.sessionApi.postCapabilities(
playableMediaTypes = listOf("Video"),
supportedCommands = listOf(
GeneralCommandType.VOLUME_UP,
GeneralCommandType.VOLUME_DOWN,
GeneralCommandType.TOGGLE_MUTE,
GeneralCommandType.SET_AUDIO_STREAM_INDEX,
GeneralCommandType.SET_SUBTITLE_STREAM_INDEX,
GeneralCommandType.MUTE,
GeneralCommandType.UNMUTE,
GeneralCommandType.SET_VOLUME,
GeneralCommandType.DISPLAY_MESSAGE,
GeneralCommandType.PLAY,
GeneralCommandType.PLAY_STATE,
GeneralCommandType.PLAY_NEXT,
GeneralCommandType.PLAY_MEDIA_SOURCE
), supportsMediaControl = true
)
}
}
override suspend fun postPlaybackStart(itemId: UUID) { override suspend fun postPlaybackStart(itemId: UUID) {
Timber.d("Sending start $itemId") Timber.d("Sending start $itemId")
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {

View file

@ -43,6 +43,9 @@ constructor(
init { init {
loadData() loadData()
viewModelScope.launch {
jellyfinRepository.postCapabilities()
}
} }
fun loadData() { fun loadData() {

View file

@ -43,31 +43,15 @@ constructor(
} }
fun connectToServer(server: Server) { fun connectToServer(server: Server) {
val jellyfinApi = JellyfinApi.newInstance(application, server.address).apply { JellyfinApi.newInstance(application, server.address).apply {
api.accessToken = server.accessToken api.accessToken = server.accessToken
userId = UUID.fromString(server.userId) userId = UUID.fromString(server.userId)
} }
viewModelScope.launch {
postCapabilities(jellyfinApi)
}
_navigateToMain.value = true _navigateToMain.value = true
} }
fun doneNavigatingToMain() { fun doneNavigatingToMain() {
_navigateToMain.value = false _navigateToMain.value = false
} }
private suspend fun postCapabilities(jellyfinApi: JellyfinApi) {
withContext(Dispatchers.IO) {
jellyfinApi.sessionApi.postCapabilities(
playableMediaTypes = listOf("Video"),
supportsMediaControl = false,
supportsSync = false,
supportsPersistentIdentifier = true
)
}
}
} }