Skip to content

Instantly share code, notes, and snippets.

@shkcodes
Created July 17, 2021 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shkcodes/8c5c68c6ee170ec8c9d742bb7df1aa12 to your computer and use it in GitHub Desktop.
Save shkcodes/8c5c68c6ee170ec8c9d742bb7df1aa12 to your computer and use it in GitHub Desktop.
@Composable
private fun updateCurrentlyPlayingItem(exoPlayer: SimpleExoPlayer, tweet: TweetItem?) {
val context = LocalContext.current
LaunchedEffect(tweet) {
exoPlayer.apply {
if (tweet != null)) {
val dataSourceFactory = DefaultDataSourceFactory(
context,
Util.getUserAgent(context, context.packageName)
)
val source = ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(MediaItem.fromUri(Uri.parse(tweet.media.url)))
setMediaSource(source)
prepare()
playWhenReady = true
} else {
stop()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment