Skip to content

Commit

Permalink
Use nextlib to be able to play mpeg-ts streams
Browse files Browse the repository at this point in the history
Fixes #7
  • Loading branch information
khaled-0 committed May 25, 2024
1 parent d0eb6e6 commit af278f0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
21 changes: 12 additions & 9 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,29 @@ android {
}

dependencies {
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.core:core-ktx:1.13.1")

implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.6.3")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-cbor:1.6.3")

implementation("androidx.core:core-splashscreen:1.0.1")

implementation(platform("androidx.compose:compose-bom:2024.02.02"))
implementation(platform("androidx.compose:compose-bom:2024.05.00"))
implementation("androidx.compose.material3:material3")
implementation("androidx.tv:tv-material:1.0.0-alpha10")
implementation("androidx.tv:tv-material:1.0.0-beta01")


implementation("io.coil-kt:coil-compose:2.6.0")
implementation("androidx.navigation:navigation-compose:2.7.7")
implementation("androidx.compose.material:material-icons-extended:1.6.3")

implementation("androidx.media3:media3-exoplayer:1.3.0")
implementation("androidx.media3:media3-exoplayer-hls:1.3.0")
implementation("androidx.media3:media3-exoplayer-dash:1.3.0")
implementation("androidx.media3:media3-ui:1.3.0")
implementation("androidx.compose.material:material-icons-extended:1.6.7")

implementation("androidx.media3:media3-exoplayer:1.3.1")
implementation("androidx.media3:media3-exoplayer-hls:1.3.1")
implementation("androidx.media3:media3-exoplayer-dash:1.3.1")
implementation("androidx.media3:media3-ui:1.3.1")
implementation("com.github.anilbeesetti.nextlib:nextlib-media3ext:0.7.1")
implementation("com.github.anilbeesetti.nextlib:nextlib-mediainfo:0.7.1")


implementation("com.github.bjoernpetersen:m3u-parser:1.4.0")
}
18 changes: 14 additions & 4 deletions app/src/main/java/dev/khaled/leanstream/player/PlayerScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dev.khaled.leanstream.player
import android.content.Context
import android.net.Uri
import androidx.activity.compose.BackHandler
import androidx.annotation.OptIn
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
Expand All @@ -12,17 +13,20 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.viewinterop.AndroidView
import androidx.media3.common.MediaItem
import androidx.media3.common.MediaMetadata
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.DefaultRenderersFactory
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.ui.PlayerView
import dev.khaled.leanstream.channels.Channel
import dev.khaled.leanstream.player.controller.PlayerController
import io.github.anilbeesetti.nextlib.media3ext.ffdecoder.NextRenderersFactory


@Composable
fun PlayerScreen(channel: Channel, playlist: List<Channel>, navigateBack: () -> Unit) {
val exoPlayer = rememberExoPlayer(LocalContext.current)

LaunchedEffect(Unit) {
// FIXME OOM When playlist large af
playlist.forEach {
exoPlayer.addMediaItem(
MediaItem.Builder().setUri(it.url).setMediaMetadata(
Expand Down Expand Up @@ -52,9 +56,15 @@ fun PlayerScreen(channel: Channel, playlist: List<Channel>, navigateBack: () ->
}


@OptIn(UnstableApi::class)
@Composable
private fun rememberExoPlayer(context: Context) = remember {
ExoPlayer.Builder(context).build().apply {
playWhenReady = true
}
val renderersFactory = NextRenderersFactory(context).setExtensionRendererMode(
DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON
)

ExoPlayer.Builder(context).setRenderersFactory(renderersFactory)
.build().apply {
playWhenReady = true
}
}
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ pluginManagement {
google()
mavenCentral()
gradlePluginPortal()
maven { url = uri("https://jitpack.io") }
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}

Expand Down

0 comments on commit af278f0

Please sign in to comment.