-
Notifications
You must be signed in to change notification settings - Fork 113
[MBL-19606][All] Enable DASH playback #3663
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
Open
kristofnemere
wants to merge
1
commit into
master
Choose a base branch
from
MBL-19606-enable-dash-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
apps/parent/src/main/java/com/instructure/parentapp/features/media/ViewMediaActivity.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * Copyright (C) 2026 - present Instructure, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, version 3 of the License. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| package com.instructure.parentapp.features.media | ||
|
|
||
| import android.content.Context | ||
| import android.content.Intent | ||
| import com.instructure.pandautils.activities.BaseViewMediaActivity | ||
| import com.instructure.pandautils.analytics.SCREEN_VIEW_VIEW_MEDIA | ||
| import com.instructure.pandautils.analytics.ScreenView | ||
| import com.instructure.pandautils.models.EditableFile | ||
|
|
||
| @ScreenView(SCREEN_VIEW_VIEW_MEDIA) | ||
| class ViewMediaActivity : BaseViewMediaActivity() { | ||
| override fun allowEditing() = false | ||
| override fun allowCopyingUrl() = false | ||
| override fun handleEditing(editableFile: EditableFile) {} | ||
|
|
||
| companion object { | ||
| fun createIntent(context: Context, url: String, contentType: String, displayName: String?): Intent { | ||
| val bundle = makeBundle(url, null, contentType, displayName, true) | ||
| return Intent(context, ViewMediaActivity::class.java).putExtras(bundle) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,9 +19,9 @@ package com.instructure.pandautils.utils | |
| import android.net.Uri | ||
| import android.view.SurfaceView | ||
| import androidx.annotation.OptIn | ||
| import androidx.core.net.toUri | ||
| import androidx.media3.common.C | ||
| import androidx.media3.common.C.TRACK_TYPE_VIDEO | ||
| import androidx.media3.common.MimeTypes | ||
| import androidx.media3.common.MediaItem | ||
| import androidx.media3.common.PlaybackException | ||
| import androidx.media3.common.PlaybackParameters | ||
|
|
@@ -84,11 +84,11 @@ class ExoAgent private constructor(val uri: Uri) { | |
| /** Whether the media track is audio only, or false if unknown */ | ||
| private var mIsAudioOnly = false | ||
|
|
||
| /** Whether we've already tried retrying with .mpd extension */ | ||
| private var triedMpdRetry = false | ||
| /** Whether we've already tried retrying as DASH */ | ||
| private var dashRetry = false | ||
|
|
||
| /** The current URI being used (may be modified for DASH retry) */ | ||
| private var currentUri: Uri = uri | ||
| /** The current PlayerView, kept so the retry can re-attach after recreating the player */ | ||
| private var mPlayerView: PlayerView? = null | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should not use hungarian notation. |
||
|
|
||
| /** The current state of this agent */ | ||
| private var currentState = ExoAgentState.IDLE | ||
|
|
@@ -98,12 +98,20 @@ class ExoAgent private constructor(val uri: Uri) { | |
|
|
||
| /** Creates a media source for the given URI */ | ||
| private fun createMediaSource(sourceUri: Uri) = run { | ||
| val mediaItem = MediaItem.fromUri(sourceUri) | ||
| when (Util.inferContentType(sourceUri)) { | ||
| C.CONTENT_TYPE_SS -> SsMediaSource.Factory(DefaultSsChunkSource.Factory(DATA_SOURCE_FACTORY), DATA_SOURCE_FACTORY).createMediaSource(mediaItem) | ||
| C.CONTENT_TYPE_DASH -> DashMediaSource.Factory(DefaultDashChunkSource.Factory(DATA_SOURCE_FACTORY), DATA_SOURCE_FACTORY).createMediaSource(mediaItem) | ||
| C.CONTENT_TYPE_HLS -> HlsMediaSource.Factory(DefaultHlsDataSourceFactory(DATA_SOURCE_FACTORY)).createMediaSource(mediaItem) | ||
| else -> ProgressiveMediaSource.Factory(DATA_SOURCE_FACTORY, DefaultExtractorsFactory()).createMediaSource(mediaItem) | ||
| // Direct CMAF/DASH URLs (e.g. Notorious) are single-use and can't be retried, so we | ||
| // detect them upfront by path suffix instead of falling back via dashRetry. | ||
| val useDash = dashRetry || sourceUri.path?.endsWith("/cmaf", ignoreCase = true) == true | ||
| if (useDash) { | ||
| val mediaItem = MediaItem.Builder().setUri(sourceUri).setMimeType(MimeTypes.APPLICATION_MPD).build() | ||
| DashMediaSource.Factory(DefaultDashChunkSource.Factory(DATA_SOURCE_FACTORY), DATA_SOURCE_FACTORY).createMediaSource(mediaItem) | ||
| } else { | ||
| val mediaItem = MediaItem.fromUri(sourceUri) | ||
| when (Util.inferContentType(sourceUri)) { | ||
| C.CONTENT_TYPE_SS -> SsMediaSource.Factory(DefaultSsChunkSource.Factory(DATA_SOURCE_FACTORY), DATA_SOURCE_FACTORY).createMediaSource(mediaItem) | ||
| C.CONTENT_TYPE_DASH -> DashMediaSource.Factory(DefaultDashChunkSource.Factory(DATA_SOURCE_FACTORY), DATA_SOURCE_FACTORY).createMediaSource(mediaItem) | ||
| C.CONTENT_TYPE_HLS -> HlsMediaSource.Factory(DefaultHlsDataSourceFactory(DATA_SOURCE_FACTORY)).createMediaSource(mediaItem) | ||
| else -> ProgressiveMediaSource.Factory(DATA_SOURCE_FACTORY, DefaultExtractorsFactory()).createMediaSource(mediaItem) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -113,6 +121,7 @@ class ExoAgent private constructor(val uri: Uri) { | |
| * NOTE: This function MUST be called before [prepare] is called by the same client. | ||
| */ | ||
| fun attach(playerView: PlayerView, listener: ExoInfoListener) { | ||
| mPlayerView = playerView | ||
| mInfoListener = listener | ||
| mInfoListener?.onStateChanged(currentState) | ||
| if (mIsAudioOnly) mInfoListener?.setAudioOnly() | ||
|
|
@@ -125,6 +134,7 @@ class ExoAgent private constructor(val uri: Uri) { | |
| * NOTE: The client MUST call [attach] prior to calling this function. | ||
| */ | ||
| fun prepare(playerView: PlayerView) { | ||
| mPlayerView = playerView | ||
| if (mPlayer == null) preparePlayer() | ||
| mPlayer?.switchSurface(playerView) | ||
| } | ||
|
|
@@ -173,21 +183,16 @@ class ExoAgent private constructor(val uri: Uri) { | |
| override fun onPlayerError(exception: PlaybackException) { | ||
| val cause = exception.cause | ||
|
|
||
| // Check if this might be a DASH video without .mpd extension | ||
| if (cause is UnrecognizedInputFormatException && | ||
| !triedMpdRetry && | ||
| !currentUri.toString().endsWith(".mpd")) { | ||
|
|
||
| // Retry with .mpd appended | ||
| triedMpdRetry = true | ||
| currentUri = "${currentUri}.mpd".toUri() | ||
|
|
||
| // Reset and retry with the new URI | ||
| // If the format wasn't recognized, retry as DASH using the same URL. | ||
| // Canvas media_download URLs generate a fresh JWT on each call so a second | ||
| // request is safe. | ||
| if (cause is UnrecognizedInputFormatException && !dashRetry) { | ||
| dashRetry = true | ||
| mPlayer?.release() | ||
| mPlayer = null | ||
| preparePlayer() | ||
| mPlayerView?.let { mPlayer?.switchSurface(it) } | ||
| } else { | ||
| // Not a retryable error, or already tried retry | ||
| reset() | ||
| mInfoListener?.onError(cause) | ||
| } | ||
|
|
@@ -210,7 +215,7 @@ class ExoAgent private constructor(val uri: Uri) { | |
| }) | ||
|
|
||
| mPlayer?.playWhenReady = true | ||
| mPlayer?.setMediaSource(createMediaSource(currentUri)) | ||
| mPlayer?.setMediaSource(createMediaSource(uri)) | ||
| mPlayer?.prepare() | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We skip error handling in this case, since it is handled in the
downloadFileToDevice.