I'm having an API serving the video URI and a (preloaded!) first frame URI. How can I initialize the ExoPlayer with the already available first frame?
@Singleton
class MediaPlayer @Inject constructor(private val context: Context) {
companion object {
var exoPlayer: SimpleExoPlayer? = null
var pauseItem = false
}
fun initializeExoplayer(uri: Uri): SimpleExoPlayer {
if (exoPlayer != null) {
resetPlayer()
}
val trackSelector = DefaultTrackSelector()
trackSelector.setParameters(
DefaultTrackSelector.ParametersBuilder()
.setForceLowestBitrate(true)
.setMaxAudioBitrate(128_000)
)
exoPlayer = ExoPlayerFactory.newSimpleInstance(context, trackSelector)
val mediaSource = createMediaSource(uri)
val loopingSource = LoopingMediaSource(mediaSource)
exoPlayer?.prepare(loopingSource)
exoPlayer?.volume = 1f
return exoPlayer!!
}
fun resetPlayer() {
exoPlayer?.playWhenReady = false
exoPlayer?.stop()
exoPlayer?.release()
exoPlayer = null
}
private fun createMediaSource(uri: Uri): MediaSource {
val userAgent = Util.getUserAgent(context, "ExoPlayerIntro")
val dataSourceFactory = DefaultDataSourceFactory(context, userAgent)
val mediaSource =
ProgressiveMediaSource.Factory(dataSourceFactory, DefaultExtractorsFactory())
.createMediaSource(uri)
return Objects.requireNonNull(mediaSource, "MediaSource cannot be null")
}
}
I've also asked the Google Team: https://github.com/google/ExoPlayer/issues/8139
from ExoPlayer how to show loading first frame during loading of video
No comments:
Post a Comment