Feroz Khan
Feroz Khan

Reputation: 2856

SimpleExoPlayer.Builder(this).build() deprecated

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?

Upvotes: 15

Views: 15788

Answers (4)

Halil Ozel
Halil Ozel

Reputation: 3332

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()

Upvotes: 7

vikas kumar
vikas kumar

Reputation: 11028

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
            )

        }
    })
}

Upvotes: 2

DragonFire
DragonFire

Reputation: 4102

In 2.16.1 do as following.

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

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

Upvotes: 4

Nitish
Nitish

Reputation: 3411

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

Upvotes: 29

Related Questions