1*30877f79SAndroid Build Coastguard Worker--- 2*30877f79SAndroid Build Coastguard Workertitle: SmoothStreaming 3*30877f79SAndroid Build Coastguard Worker--- 4*30877f79SAndroid Build Coastguard Worker 5*30877f79SAndroid Build Coastguard Worker{% include_relative _page_fragments/supported-formats-smoothstreaming.md %} 6*30877f79SAndroid Build Coastguard Worker 7*30877f79SAndroid Build Coastguard Worker## Using MediaItem ## 8*30877f79SAndroid Build Coastguard Worker 9*30877f79SAndroid Build Coastguard WorkerTo play a SmoothStreaming stream, you need to depend on the SmoothStreaming 10*30877f79SAndroid Build Coastguard Workermodule. 11*30877f79SAndroid Build Coastguard Worker 12*30877f79SAndroid Build Coastguard Worker~~~ 13*30877f79SAndroid Build Coastguard Workerimplementation 'com.google.android.exoplayer:exoplayer-smoothstreaming:2.X.X' 14*30877f79SAndroid Build Coastguard Worker~~~ 15*30877f79SAndroid Build Coastguard Worker{: .language-gradle} 16*30877f79SAndroid Build Coastguard Worker 17*30877f79SAndroid Build Coastguard WorkerYou can then create a `MediaItem` for a SmoothStreaming manifest URI and pass it 18*30877f79SAndroid Build Coastguard Workerto the player. 19*30877f79SAndroid Build Coastguard Worker 20*30877f79SAndroid Build Coastguard Worker~~~ 21*30877f79SAndroid Build Coastguard Worker// Create a player instance. 22*30877f79SAndroid Build Coastguard WorkerExoPlayer player = new ExoPlayer.Builder(context).build(); 23*30877f79SAndroid Build Coastguard Worker// Set the media item to be played. 24*30877f79SAndroid Build Coastguard Workerplayer.setMediaItem(MediaItem.fromUri(ssUri)); 25*30877f79SAndroid Build Coastguard Worker// Prepare the player. 26*30877f79SAndroid Build Coastguard Workerplayer.prepare(); 27*30877f79SAndroid Build Coastguard Worker~~~ 28*30877f79SAndroid Build Coastguard Worker{: .language-java} 29*30877f79SAndroid Build Coastguard Worker 30*30877f79SAndroid Build Coastguard WorkerIf your URI doesn't end with `.ism/Manifest`, you can pass 31*30877f79SAndroid Build Coastguard Worker`MimeTypes.APPLICATION_SS` to `setMimeType` of `MediaItem.Builder` to explicitly 32*30877f79SAndroid Build Coastguard Workerindicate the type of the content. 33*30877f79SAndroid Build Coastguard Worker 34*30877f79SAndroid Build Coastguard WorkerExoPlayer will automatically adapt between representations defined in the 35*30877f79SAndroid Build Coastguard Workermanifest, taking into account both available bandwidth and device capabilities. 36*30877f79SAndroid Build Coastguard Worker 37*30877f79SAndroid Build Coastguard Worker## Using SsMediaSource ## 38*30877f79SAndroid Build Coastguard Worker 39*30877f79SAndroid Build Coastguard WorkerFor more customization options, you can create a `SsMediaSource` and pass it 40*30877f79SAndroid Build Coastguard Workerdirectly to the player instead of a `MediaItem`. 41*30877f79SAndroid Build Coastguard Worker 42*30877f79SAndroid Build Coastguard Worker~~~ 43*30877f79SAndroid Build Coastguard Worker// Create a data source factory. 44*30877f79SAndroid Build Coastguard WorkerDataSource.Factory dataSourceFactory = new DefaultHttpDataSource.Factory(); 45*30877f79SAndroid Build Coastguard Worker// Create a SmoothStreaming media source pointing to a manifest uri. 46*30877f79SAndroid Build Coastguard WorkerMediaSource mediaSource = 47*30877f79SAndroid Build Coastguard Worker new SsMediaSource.Factory(dataSourceFactory) 48*30877f79SAndroid Build Coastguard Worker .createMediaSource(MediaItem.fromUri(ssUri)); 49*30877f79SAndroid Build Coastguard Worker// Create a player instance. 50*30877f79SAndroid Build Coastguard WorkerExoPlayer player = new ExoPlayer.Builder(context).build(); 51*30877f79SAndroid Build Coastguard Worker// Set the media source to be played. 52*30877f79SAndroid Build Coastguard Workerplayer.setMediaSource(mediaSource); 53*30877f79SAndroid Build Coastguard Worker// Prepare the player. 54*30877f79SAndroid Build Coastguard Workerplayer.prepare(); 55*30877f79SAndroid Build Coastguard Worker~~~ 56*30877f79SAndroid Build Coastguard Worker{: .language-java} 57*30877f79SAndroid Build Coastguard Worker 58*30877f79SAndroid Build Coastguard Worker## Accessing the manifest ## 59*30877f79SAndroid Build Coastguard Worker 60*30877f79SAndroid Build Coastguard WorkerYou can retrieve the current manifest by calling `Player.getCurrentManifest`. 61*30877f79SAndroid Build Coastguard WorkerFor SmoothStreaming you should cast the returned object to `SsManifest`. The 62*30877f79SAndroid Build Coastguard Worker`onTimelineChanged` callback of `Player.Listener` is also called whenever 63*30877f79SAndroid Build Coastguard Workerthe manifest is loaded. This will happen once for a on-demand content, and 64*30877f79SAndroid Build Coastguard Workerpossibly many times for live content. The code snippet below shows how an app 65*30877f79SAndroid Build Coastguard Workercan do something whenever the manifest is loaded. 66*30877f79SAndroid Build Coastguard Worker 67*30877f79SAndroid Build Coastguard Worker~~~ 68*30877f79SAndroid Build Coastguard Workerplayer.addListener( 69*30877f79SAndroid Build Coastguard Worker new Player.Listener() { 70*30877f79SAndroid Build Coastguard Worker @Override 71*30877f79SAndroid Build Coastguard Worker public void onTimelineChanged( 72*30877f79SAndroid Build Coastguard Worker Timeline timeline, @Player.TimelineChangeReason int reason) { 73*30877f79SAndroid Build Coastguard Worker Object manifest = player.getCurrentManifest(); 74*30877f79SAndroid Build Coastguard Worker if (manifest != null) { 75*30877f79SAndroid Build Coastguard Worker SsManifest ssManifest = (SsManifest) manifest; 76*30877f79SAndroid Build Coastguard Worker // Do something with the manifest. 77*30877f79SAndroid Build Coastguard Worker } 78*30877f79SAndroid Build Coastguard Worker } 79*30877f79SAndroid Build Coastguard Worker }); 80*30877f79SAndroid Build Coastguard Worker~~~ 81*30877f79SAndroid Build Coastguard Worker{: .language-java} 82*30877f79SAndroid Build Coastguard Worker 83*30877f79SAndroid Build Coastguard Worker## Customizing playback ## 84*30877f79SAndroid Build Coastguard Worker 85*30877f79SAndroid Build Coastguard WorkerExoPlayer provides multiple ways for you to tailor playback experience to your 86*30877f79SAndroid Build Coastguard Workerapp's needs. See the [Customization page][] for examples. 87*30877f79SAndroid Build Coastguard Worker 88*30877f79SAndroid Build Coastguard Worker[Customization page]: {{ site.baseurl }}/customization.html 89