Skip to content

Commit becfe96

Browse files
handle mp4 links for playing video
1 parent e557556 commit becfe96

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

course/src/main/java/org/openedx/course/presentation/unit/video/VideoUnitFragment.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,9 @@ class VideoUnitFragment : Fragment(R.layout.fragment_video_unit) {
198198
val movieMetadata = MediaMetadata.Builder()
199199
.setMediaType(MediaMetadata.MEDIA_TYPE_MOVIE)
200200
.build()
201+
val normalizedUrl = normalizeUrl(viewModel.videoUrl)
201202
val mediaItem = MediaItem.Builder().setMediaMetadata(movieMetadata)
202-
.setUri(viewModel.videoUrl)
203+
.setUri(normalizedUrl)
203204
.setMimeType("video/*")
204205
.build()
205206

@@ -292,6 +293,19 @@ class VideoUnitFragment : Fragment(R.layout.fragment_video_unit) {
292293
}
293294
}
294295

296+
// Convert to https when possible (helps avoid cleartext/network-security issues).
297+
private fun normalizeUrl(url: String?): String? {
298+
if (url.isNullOrBlank()) return url
299+
val trimmed = url.trim()
300+
return try {
301+
if (trimmed.startsWith("http://", ignoreCase = true)) {
302+
trimmed.replaceFirst("http://", "https://", ignoreCase = true)
303+
} else trimmed
304+
} catch (e: Exception) {
305+
trimmed
306+
}
307+
}
308+
295309
companion object {
296310
private const val ARG_BLOCK_ID = "blockId"
297311
private const val ARG_VIDEO_URL = "videoUrl"

0 commit comments

Comments
 (0)