Skip to content
Merged
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 @@ -198,8 +198,9 @@
val movieMetadata = MediaMetadata.Builder()
.setMediaType(MediaMetadata.MEDIA_TYPE_MOVIE)
.build()
val normalizedUrl = normalizeUrl(viewModel.videoUrl)
val mediaItem = MediaItem.Builder().setMediaMetadata(movieMetadata)
.setUri(viewModel.videoUrl)
.setUri(normalizedUrl)
.setMimeType("video/*")
.build()

Expand Down Expand Up @@ -279,7 +280,7 @@

@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
private fun setPlayerMedia(mediaItem: MediaItem) {
if (viewModel.videoUrl.endsWith(".m3u8")) {
if (viewModel.videoUrl.contains(".m3u8", ignoreCase = true)) {
val factory = DefaultDataSource.Factory(requireContext())
val mediaSource: HlsMediaSource =
HlsMediaSource.Factory(factory).createMediaSource(mediaItem)
Expand All @@ -292,6 +293,19 @@
}
}

// Convert to https when possible (helps avoid cleartext/network-security issues).
private fun normalizeUrl(url: String?): String? {
if (url.isNullOrBlank()) return url
val trimmed = url.trim()
return try {
if (trimmed.startsWith("http://", ignoreCase = true)) {
trimmed.replaceFirst("http://", "https://", ignoreCase = true)
} else trimmed

Check warning

Code scanning / detekt

Detects multiline if-else statements without braces Warning

Missing { ... }
} catch (e: Exception) {

Check warning

Code scanning / detekt

The caught exception is swallowed. The original exception could be lost. Warning

The caught exception is swallowed. The original exception could be lost.
trimmed
}
}

companion object {
private const val ARG_BLOCK_ID = "blockId"
private const val ARG_VIDEO_URL = "videoUrl"
Expand Down
Loading