Skip to content

Instantly share code, notes, and snippets.

@aartikov
Created October 1, 2018 05:16
Show Gist options
  • Save aartikov/accb92f99a81ce787b31175b12b1ad22 to your computer and use it in GitHub Desktop.
Save aartikov/accb92f99a81ce787b31175b12b1ad22 to your computer and use it in GitHub Desktop.
ExoPlayer
private lateinit var player: ExoPlayer
private lateinit var mediaSourceFactory: ExtractorMediaSource.Factory
private fun initPlayer() {
val bandwidthMeter = DefaultBandwidthMeter()
val videoTrackSelectionFactory = AdaptiveTrackSelection.Factory(bandwidthMeter)
val trackSelector = DefaultTrackSelector(videoTrackSelectionFactory)
val dataSourceFactory = DefaultDataSourceFactory(context, Util.getUserAgent(context, "A"))
mediaSourceFactory = ExtractorMediaSource.Factory(dataSourceFactory).setExtractorsFactory(DefaultExtractorsFactory())
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector)
playerView.player = player
player.playWhenReady = true
}
private fun playVideo(filePath: String) {
val uri = Uri.parse("http://techslides.com/demos/samples/sample.mov") //Uri.fromFile(File(filePath))
val mediaSource = mediaSourceFactory.createMediaSource(uri)
player.prepare(mediaSource)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment