Skip to content

Instantly share code, notes, and snippets.

@tizisdeepan
Created June 10, 2019 09:03
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 tizisdeepan/0b3a32f3a333c0268be0d1dc0e24adc4 to your computer and use it in GitHub Desktop.
Save tizisdeepan/0b3a32f3a333c0268be0d1dc0e24adc4 to your computer and use it in GitHub Desktop.
val mainHandler = Handler()
val url = "YOUR_VIDEO_URL"
val bandwidthMeter = DefaultBandwidthMeter()
val videoTrackSelectionFactory = AdaptiveTrackSelection.Factory(bandwidthMeter)
val trackSelector = DefaultTrackSelector(videoTrackSelectionFactory)
val player = ExoPlayerFactory.newSimpleInstance(this, trackSelector)
videoView.player = player
val dataSourceFactory = DefaultDataSourceFactory(this, Util.getUserAgent(this, "ZohoSocial"), bandwidthMeter)
val videoSource = if (url.contains(".m3u8")) HlsMediaSource(Uri.parse(url), dataSourceFactory, mainHandler, null)
else ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(url))
player.prepare(videoSource)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment