SimpleExoPlayer.Builder(this).build() deprecated
Asked Answered
T

4

15

I'm using Exoplayer in my app and initializing exoplayer as

player = SimpleExoPlayer.Builder(this).build()

But Android Studio is giving me warning as it is deprecated. When I get to the lower version of Exoplayer 2.15.1, then warning goes off. But in latest version 2.16.0, it is giving deprecation warning. How can we initialize exoplayer now with the latest version?

Tailor answered 24/11, 2021 at 10:59 Comment(1)
As per the release notes for 2.16.0: Deprecate SimpleExoPlayer. All functionality has been moved to ExoPlayer instead. ExoPlayer.Builder can be used instead of SimpleExoPlayer.Builder. You can find further changes here github.com/google/ExoPlayer/releasesNigrescent
N
29

SimpleExoPlayer Deprecated. All functionality has been moved to ExoPlayer instead. ExoPlayer.Builder can be used instead of SimpleExoPlayer.Builder.

Initialize your exoplayer as

player = ExoPlayer.Builder(this).build()

You can check the changes done in library for version 2.16.0 in release notes

Nonpayment answered 24/11, 2021 at 11:9 Comment(0)
F
7

SimpleExoPlayer deprecated. You should use ExoPlayer

implementation 'com.google.android.exoplayer:exoplayer:2.18.2'

Example:

private var exoPlayer: ExoPlayer? = null
exoPlayer = ExoPlayer.Builder(this).build()
Francescafrancesco answered 8/1, 2022 at 20:9 Comment(0)
H
4

In 2.16.1 do as following.

ExoPlayer player = new ExoPlayer.Builder(context).build();

Pls see : https://exoplayer.dev/hello-world.html

Hammons answered 7/2, 2022 at 0:12 Comment(0)
S
2

player intialization.

val exoPlayer = ExoPlayer.Builder(context).build().apply {
    setMediaItem(MediaItem.fromUri("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"))
}

and PlayerView is now replaced with StyledPlayerView

StyledPlayerView(context).apply {
            player = exoPlayer
            layoutParams = FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT
            )

        }

Compose example below.

@Composable
fun VideoPlayer() {
    val context = LocalContext.current
    val exoPlayer = remember(context) {
        ExoPlayer.Builder(context).build().apply {
            setMediaItem(MediaItem.fromUri("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"))
        }
    }

    DisposableEffect(key1 = exoPlayer) {
        onDispose {
            exoPlayer.release()
        }
    }

    AndroidView(modifier = Modifier
        .fillMaxWidth()
        .height(214.dp), factory = {
        StyledPlayerView(context).apply {
            player = exoPlayer
            layoutParams = FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT
            )

        }
    })
}
Stagehand answered 5/8, 2022 at 19:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.