Skip to content

Commit

Permalink
280 load drm token protected examples in the demo (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
StaehliJ authored Nov 1, 2023
1 parent 60e431c commit 0dfd225
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,7 @@ data class Playlist(val title: String, val items: List<DemoItem>, val descriptio
DemoItem.OnDemandHorizontalVideo,
DemoItem.OnDemandSquareVideo,
DemoItem.OnDemandVerticalVideo,
DemoItem.TokenProtectedVideo,
DemoItem.SuperfluouslyTokenProtectedVideo,
DemoItem.DrmProtectedVideo,
DemoItem.LiveVideo,
DemoItem.DvrVideo,
DemoItem.DvrAudio,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2023. SRG SSR. All rights reserved.
* License information is available from the LICENSE file.
*/
package ch.srgssr.pillarbox.demo.ui.examples

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import ch.srg.dataProvider.integrationlayer.request.parameters.Bu
import ch.srgssr.pillarbox.demo.shared.data.DemoItem
import ch.srgssr.pillarbox.demo.shared.data.Playlist
import ch.srgssr.pillarbox.demo.ui.integrationLayer.data.ILRepository
import ch.srgssr.pillarbox.demo.ui.integrationLayer.di.IntegrationLayerModule
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.stateIn

/**
* Example view model
*
* @param application Android Application to create [ILRepository]
*/
class ExampleViewModel(application: Application) : AndroidViewModel(application) {
private val repository: ILRepository = IntegrationLayerModule.createIlRepository(application)

/**
* Contents to display
*/
val contents: StateFlow<List<Playlist>> = flow {
val listDrmContent = repository.getLatestMediaByShowUrn(SHOW_URN, 2).getOrDefault(emptyList())
val listTokenProtectedContent = repository.getTvLiveCenter(Bu.RTS, 2).getOrDefault(emptyList())
val playlist = Playlist(
title = PROTECTED_CONTENT_TITLE,
items = (listDrmContent + listTokenProtectedContent).map { DemoItem(title = it.title, description = it.lead, uri = it.urn) }
)
emit(LIST_STATIC_PLAYLIST + playlist)
}.stateIn(viewModelScope, started = SharingStarted.Eagerly, LIST_STATIC_PLAYLIST)

companion object {
private const val SHOW_URN = "urn:rts:show:tv:532539"
private const val PROTECTED_CONTENT_TITLE = "Protected contents"

private val LIST_STATIC_PLAYLIST = listOf(
Playlist.StreamUrls,
Playlist.StreamUrns,
Playlist.PlaySuisseStreams,
Playlist.StreamApples,
Playlist.StreamGoogles,
Playlist.BitmovinSamples,
Playlist.UnifiedStreaming,
Playlist.UnifiedStreamingDash,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ import androidx.compose.material3.Card
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import ch.srgssr.pillarbox.demo.BuildConfig
import ch.srgssr.pillarbox.demo.shared.data.DemoItem
import ch.srgssr.pillarbox.demo.shared.data.Playlist
Expand All @@ -38,20 +39,10 @@ import ch.srgssr.pillarbox.demo.ui.theme.PillarboxTheme
*/
@Composable
fun ExamplesHome() {
val exampleViewModel: ExampleViewModel = viewModel()
val context = LocalContext.current
val listItems = remember {
listOf(
Playlist.StreamUrls,
Playlist.StreamUrns,
Playlist.PlaySuisseStreams,
Playlist.StreamApples,
Playlist.StreamGoogles,
Playlist.BitmovinSamples,
Playlist.UnifiedStreaming,
Playlist.UnifiedStreamingDash,
)
}
ListStreamView(playlistList = listItems) {
val listItems = exampleViewModel.contents.collectAsState()
ListStreamView(playlistList = listItems.value) {
SimplePlayerActivity.startActivity(context, it)
}
}
Expand Down Expand Up @@ -90,7 +81,12 @@ private fun ListStreamView(playlistList: List<Playlist>, onItemClicked: (DemoIte
}
}
}
Box(modifier = Modifier.fillMaxWidth().padding(12.dp), contentAlignment = Alignment.Center) {
Box(
modifier = Modifier
.fillMaxWidth()
.padding(12.dp),
contentAlignment = Alignment.Center
) {
Text(text = BuildConfig.VERSION_NAME, style = MaterialTheme.typography.bodyLarge, fontStyle = FontStyle.Italic)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import ch.srg.dataProvider.integrationlayer.data.remote.Transmission
import ch.srg.dataProvider.integrationlayer.request.IlService
import ch.srg.dataProvider.integrationlayer.request.parameters.Bu
import ch.srg.dataProvider.integrationlayer.request.parameters.IlMediaType
import ch.srg.dataProvider.integrationlayer.request.parameters.IlPaging.Unlimited.toIlPaging
import ch.srg.dataProvider.integrationlayer.request.parameters.IlTransmission
import ch.srgssr.dataprovider.paging.DataProviderPaging
import ch.srgssr.dataprovider.paging.datasource.NextUrlPagingSource
Expand Down Expand Up @@ -98,6 +99,17 @@ class ILRepository(
return dataProviderPaging.getLatestMediaByShowUrn(showUrn = urn, pageSize = PAGE_SIZE)
}

/**
* Get latest media by show urn
*
* @param urn
* @param pageSize
* @return
*/
suspend fun getLatestMediaByShowUrn(urn: String, pageSize: Int): Result<List<Media>> {
return runCatching { ilService.getLatestMediaByShowUrn(urn, pageSize.toIlPaging()).list }
}

/**
* Get latest media by topic urn
*
Expand Down Expand Up @@ -153,6 +165,17 @@ class ILRepository(
return dataProviderPaging.getLiveCenterVideos(bu = bu, pageSize = PAGE_SIZE, type = LiveCenterType.SCHEDULED_LIVESTREAM)
}

/**
* Get tv live center
*
* @param bu
* @param pageSize
* @return
*/
suspend fun getTvLiveCenter(bu: Bu, pageSize: Int): Result<List<Media>> {
return runCatching { ilService.getLiveCenterVideos(bu = bu, pageSize = pageSize.toIlPaging()).list }
}

/**
* Search
*
Expand Down

0 comments on commit 0dfd225

Please sign in to comment.