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