Skip to content

Instantly share code, notes, and snippets.

@ponnamkarthik
Last active April 17, 2018 13:50
Show Gist options
  • Save ponnamkarthik/af294de0f821ebbdee5d2736345b8864 to your computer and use it in GitHub Desktop.
Save ponnamkarthik/af294de0f821ebbdee5d2736345b8864 to your computer and use it in GitHub Desktop.
RTMP Player using Exo Media Player Library
//initiate Player
//Create a default TrackSelector
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
//Create the player
SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
PlayerView playerView = findViewById(R.id.simple_player);
playerView.setPlayer(player);
RtmpDataSourceFactory rtmpDataSourceFactory = new RtmpDataSourceFactory();
// This is the MediaSource representing the media to be played.
MediaSource videoSource = new ExtractorMediaSource.Factory(rtmpDataSourceFactory)
.createMediaSource(Uri.parse("rtmp://stream1.livestreamingservices.com:1935/tvmlive/tvmlive"));
// Prepare the player with the source.
player.prepare(videoSource);
//auto start playing
player.setPlayWhenReady(true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment