Created
October 1, 2018 05:16
-
-
Save aartikov/accb92f99a81ce787b31175b12b1ad22 to your computer and use it in GitHub Desktop.
ExoPlayer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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