after updating to the latest build version of ExoPlayer i.e "2.18.1", ExoPlayerFactory.newSimpleInstance showing unresolved reference Error,
Want to reformat this Initialize Function to the latest version of exoplayer without changing its Logic
getting obscured errors in function
private fun initializeExoPlayer(soundFile: String): ExoPlayer {
// create the player
val exoPlayer = ExoPlayerFactory.newSimpleInstance(
DefaultRenderersFactory(this), DefaultTrackSelector()
)
// load the media source
val dataSource = DefaultDataSourceFactory(this,
Util.getUserAgent(this, this.getString(R.string.app_name)))
val mediaSource = ProgressiveMediaSource.Factory(dataSource)
.createMediaSource(Uri.parse("asset:///$soundFile"))
// load the media
Log.d("MAIN", "loading $soundFile")
exoPlayer.prepare(mediaSource)
// loop indefinitely
exoPlayer.repeatMode = Player.REPEAT_MODE_ALL
return exoPlayer
}
the errors are
.createMediaSource(Uri.parse("asset:///$soundFile"))
exoPlayer.repeatMode = Player.REPEAT_MODE_ALL
gradle:
// ExoPlayer
api "com.google.android.exoplayer:exoplayer-core:2.18.1"
api "com.google.android.exoplayer:exoplayer-ui:2.18.1"
api "com.google.android.exoplayer:extension-mediasession:2.18.1"
TRIED after searching multiple times changed the following function into ->
private fun initializeExoPlayer(soundFile: String): ExoPlayer {
// create the player
val exoPlayer = ExoPlayer.Builder(this).build()
// load the media source
val dataSource = DefaultDataSourceFactory(this,
Util.getUserAgent(this, this.getString(R.string.app_name)))
val firstAudioUri = Uri.parse("assets:///$soundFile")
val mediaSource = MediaItem.fromUri(firstAudioUri)
// load the media
Log.d("MAIN", "loading $soundFile")
exoPlayer.addMediaItem(mediaSource)
exoPlayer.prepare()
// loop indefinitely
exoPlayer.repeatMode = Player.REPEAT_MODE_ALL
return exoPlayer
}
all the indicated Errors were gone but no media is playing and Variable 'dataSource' is never used
Any help would be highly appreciated.
i Tried this, and its working fine now.
private fun initializeExoPlayer(soundFile: String): ExoPlayer {
// create the player
val trackSelector = DefaultTrackSelector(this)
val exoPlayer = ExoPlayer.Builder(this).setTrackSelector(trackSelector).build()
// load the media source
val dataSource = DefaultDataSource.Factory(this)
val mediaSource = ProgressiveMediaSource.Factory(dataSource)
.createMediaSource(MediaItem.fromUri(Uri.parse("asset:///$soundFile")))
// load the media
Log.d("MAIN", "loading $soundFile")
exoPlayer.setMediaSource(mediaSource)
exoPlayer.prepare()
// loop indefinitely
exoPlayer.repeatMode = Player.REPEAT_MODE_ALL
return exoPlayer
}