Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide content type to Exoplayer attachSource for initialization #46

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package com.fivegmag.a5gmsmediastreamhandler

import android.content.Context
import androidx.media3.common.MediaItem
import androidx.media3.common.MimeTypes
import androidx.media3.common.Player
import androidx.media3.common.util.UnstableApi
import androidx.media3.common.util.Util
Expand All @@ -22,6 +23,7 @@ import androidx.media3.exoplayer.source.DefaultMediaSourceFactory
import androidx.media3.exoplayer.upstream.DefaultBandwidthMeter
import androidx.media3.exoplayer.util.EventLogger
import androidx.media3.ui.PlayerView
import com.fivegmag.a5gmscommonlibrary.helpers.ContentTypes
import com.fivegmag.a5gmscommonlibrary.helpers.PlayerStates
import com.fivegmag.a5gmscommonlibrary.helpers.StatusInformation
import com.fivegmag.a5gmscommonlibrary.helpers.UserAgentTokens
Expand Down Expand Up @@ -71,8 +73,26 @@ class ExoPlayerAdapter() {
playerInstance.addListener(playerListener)
}

fun attach(url: String) {
val mediaItem: MediaItem = MediaItem.fromUri(url)
fun attach(url: String, contentType: String = "") {
val mediaItem : MediaItem
when (contentType) {
ContentTypes.DASH -> {
mediaItem = MediaItem.Builder()
.setUri(url)
.setMimeType(MimeTypes.APPLICATION_MPD)
.build()
}
ContentTypes.HLS -> {
mediaItem = MediaItem.Builder()
.setUri(url)
.setMimeType(MimeTypes.APPLICATION_M3U8)
.build()
}
else -> {
mediaItem = MediaItem.fromUri(url)
}
}

playerInstance.setMediaItem(mediaItem)
activeMediaItem = mediaItem
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ class MediaSessionHandlerAdapter() {
entryPoints.filter { entryPoint -> entryPoint.contentType == ContentTypes.DASH }

if (dashEntryPoints.isNotEmpty()) {
startPlayback(dashEntryPoints[0].locator)
startPlayback(dashEntryPoints[0].locator, ContentTypes.DASH)
}
}
}

private fun startPlayback(url: String) {
exoPlayerAdapter.attach(url)
private fun startPlayback(url: String, contentType: String) {
exoPlayerAdapter.attach(url, contentType)
exoPlayerAdapter.preload()
exoPlayerAdapter.play()
}
Expand Down
Loading