Skip to content

MediaApiManager(Kotlin)

Ray edited this page Aug 24, 2021 · 1 revision

Overview

This page show how to use MediaApiManager.

MediaApiManager can be used to fetch Straas media information.

If you haven't read MediaCore(Kotlin), please read it first.

Create MediaApiManager

  • Use straasCore.createMediaApiManager to create a MediaApiManager first:
val mediaApiManager = StraasCore.getInstance(context).createMediaApiManager(StraasMember.GUEST)

Fetching video information by MediaApiManager

All of these requests are implemented in suspend function, so you need to execute these functions in a CoroutineScope. We use lifecyclescope as an example in this page.

Get Live event information

lifecycleScope.launch {
    try {
        val liveInfo = mediaApiManager.getLive(liveEventId)
    } catch (e: Exception) {
        // handle exception
    }
}

Get listing information

  • Get public live event list
lifecycleScope.launch {
    val listData = mMediaApiManager.getLiveList()
}

We won't load all the live event once because there are too many live events. You can use getLiveListByPageUrl with the pageUrl in last page to get the next page.

Note. ListData.nextPageUrl may be null if there is no next page.

lifecycleScope.launch {
    listData.nextPageUrl?.let { pageUrl ->
        mMediaApiManager.getLiveListByPageUrl(pageUrl)   
    }?: kotlin.run { 
        // handle no next page url
    }
}
  • Get VOD of live event

You can also get the VOD of live event by MediaApiManager.getVideoListOfLive:

lifecycleScope.launch {
    val listData = mMediaApiManager.getVideoListOfLive(liveId)
}