Skip to content

Commit

Permalink
new: Add max and min playback resolution (#17)
Browse files Browse the repository at this point in the history
* Max res and rendition order added.

* Fix the build

* Update example

* Revert "Update example"

This reverts commit 9297bf1.

* update

---------

Co-authored-by: Emily Dixon <edixon@mux.com>
  • Loading branch information
tomkordic and daytime-em authored Nov 17, 2023
1 parent 496ae2c commit 7dc45f6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import com.mux.stats.sdk.core.model.CustomerViewData
import com.mux.stats.sdk.core.util.UUID
import com.mux.player.MuxPlayer
import com.mux.player.media.MediaItems
import com.mux.player.media.PlaybackMaxResolution
import com.mux.player.media.PlaybackResolution
import com.mux.player.media3.PlaybackIds
import com.mux.player.media3.databinding.ActivityBasicPlayerBinding

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import com.mux.stats.sdk.core.model.CustomerViewData
import com.mux.stats.sdk.core.util.UUID
import com.mux.player.MuxPlayer
import com.mux.player.media.MediaItems
import com.mux.player.media.PlaybackMaxResolution
import com.mux.player.media.PlaybackResolution
import com.mux.player.media3.PlaybackIds
import com.mux.player.media3.databinding.ActivityBasicPlayerBinding

Expand Down Expand Up @@ -59,7 +59,7 @@ class MaxResActivity : AppCompatActivity() {
val player = createPlayer(this)
val mediaItem = MediaItems.builderFromMuxPlaybackId(
PlaybackIds.TEARS_OF_STEEL,
PlaybackMaxResolution.UP_TO_720p,
maxResolution = PlaybackResolution.HD_720,
)
.setMediaMetadata(
MediaMetadata.Builder()
Expand Down
60 changes: 42 additions & 18 deletions library/src/main/java/com/mux/player/media/MediaItems.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ object MediaItems {
@JvmOverloads
fun fromMuxPlaybackId(
playbackId: String,
maxResolution: PlaybackMaxResolution? = null,
maxResolution: PlaybackResolution? = null,
minResolution: PlaybackResolution? = null,
renditionOrder: RenditionOrder? = null,
domain: String = MUX_VIDEO_DEFAULT_DOMAIN,
playbackToken: String? = null,
): MediaItem = builderFromMuxPlaybackId(
playbackId,
maxResolution,
minResolution,
renditionOrder,
domain,
playbackToken,
).build()
Expand All @@ -56,7 +60,9 @@ object MediaItems {
@JvmOverloads
fun builderFromMuxPlaybackId(
playbackId: String,
maxResolution: PlaybackMaxResolution? = null,
maxResolution: PlaybackResolution? = null,
minResolution: PlaybackResolution? = null,
renditionOrder: RenditionOrder? = null,
domain: String = MUX_VIDEO_DEFAULT_DOMAIN,
playbackToken: String? = null,
): MediaItem.Builder {
Expand All @@ -66,6 +72,8 @@ object MediaItems {
playbackId = playbackId,
domain = domain,
maxResolution = maxResolution,
minResolution = minResolution,
renditionOrder = renditionOrder,
playbackToken = playbackToken,
)
)
Expand All @@ -79,23 +87,36 @@ object MediaItems {
playbackId: String,
domain: String = MUX_VIDEO_DEFAULT_DOMAIN,
subdomain: String = MUX_VIDEO_SUBDOMAIN,
maxResolution: PlaybackMaxResolution? = null,
maxResolution: PlaybackResolution? = null,
minResolution: PlaybackResolution? = null,
renditionOrder: RenditionOrder? = null,
playbackToken: String? = null,
): String {
val base = Uri.parse("https://$subdomain.$domain/$playbackId.m3u8").buildUpon()

minResolution?.let { base.appendQueryParameter("min_resolution", resolutionValue(it)) }
maxResolution?.let { base.appendQueryParameter("max_resolution", resolutionValue(it)) }
renditionOrder?.let { base.appendQueryParameter("rendition_order", resolutionValue(it)) }
playbackToken?.let { base.appendQueryParameter("token", it) }

return base.build().toString()
}

private fun resolutionValue(playbackMaxResolution: PlaybackMaxResolution): String {
return when (playbackMaxResolution) {
PlaybackMaxResolution.UP_TO_720p -> "720p"
PlaybackMaxResolution.UP_TO_1080p -> "1080p"
PlaybackMaxResolution.UP_TO_1440p -> "1440p"
PlaybackMaxResolution.UP_TO_2160p -> "2160p"
private fun resolutionValue(renditionOrder: RenditionOrder): String {
return when (renditionOrder) {
RenditionOrder.Ascending -> "asc"
RenditionOrder.Descending -> "desc"
}
}

private fun resolutionValue(playbackResolution: PlaybackResolution): String {
return when (playbackResolution) {
PlaybackResolution.LD_480 -> "480p"
PlaybackResolution.LD_540 -> "540p"
PlaybackResolution.HD_720 -> "720p"
PlaybackResolution.FHD_1080 -> "1080p"
PlaybackResolution.QHD_1440 -> "1440p"
PlaybackResolution.FOUR_K_2160 -> "2160p"
}
}
}
Expand All @@ -104,13 +125,16 @@ object MediaItems {
* A resolution for playing back Mux assets. If specified in [MediaItems.fromMuxPlaybackId], or
* similar methods, the video's resolution will be limited to the given value
*/
enum class PlaybackMaxResolution {
@Suppress("EnumEntryName") // lower-case matches industry-standard casing for resolutions
UP_TO_720p,
@Suppress("EnumEntryName") // lower-case matches industry-standard casing for resolutions
UP_TO_1080p,
@Suppress("EnumEntryName") // lower-case matches industry-standard casing for resolutions
UP_TO_1440p,
@Suppress("EnumEntryName") // lower-case matches industry-standard casing for resolutions
UP_TO_2160p,
enum class PlaybackResolution {
LD_480,
LD_540,
HD_720,
FHD_1080,
QHD_1440,
FOUR_K_2160,
}

enum class RenditionOrder {
Ascending,
Descending,
}

0 comments on commit 7dc45f6

Please sign in to comment.