media/extensions/icy
Sascha Peilicke 95eff3b747 Add Shoutcast Metadata Protocol (ICY) extension
Based on the OkHttp extension.

Resolves #3735
2018-10-22 23:22:41 +02:00
..
src Add Shoutcast Metadata Protocol (ICY) extension 2018-10-22 23:22:41 +02:00
build.gradle Add Shoutcast Metadata Protocol (ICY) extension 2018-10-22 23:22:41 +02:00
proguard-rules.txt Add Shoutcast Metadata Protocol (ICY) extension 2018-10-22 23:22:41 +02:00
README.md Add Shoutcast Metadata Protocol (ICY) extension 2018-10-22 23:22:41 +02:00

ExoPlayer Shoutcast Metadata Protocol (ICY) extension

The Shoutcast Metadata Protocol extension provides IcyHttpDataSource and IcyHttpDataSourceFactory which can parse ICY metadata information such as stream name and genre as well as current song information from a music stream.

You can find the protocol description here:

Getting the extension

The easiest way to use the extension is to add it as a gradle dependency:

implementation 'com.google.android.exoplayer:extension-icy:2.X.X'

where 2.X.X is the version, which must match the version of the ExoPlayer library being used.

Alternatively, you can clone the ExoPlayer repository and depend on the module locally. Instructions for doing this can be found in ExoPlayer's top level README.

Using the extension

To receive information about the current music stream (such as name and genre, see IcyHeaders class) as well as current song information (see IcyMetadata class), pass an instance of IcyHttpDataSourceFactory instead of an DefaultHttpDataSourceFactory like this (in Kotlin):

// ... exoPlayer instance already created

// Custom HTTP data source factory which requests Icy metadata and parses it if
// the stream server supports it
val client = OkHttpClient.Builder().build()
val icyHttpDataSourceFactory = IcyHttpDataSourceFactory.Builder(client)
    .setUserAgent(userAgent)
    .setIcyHeadersListener { icyHeaders ->
        Log.d("XXX", "onIcyHeaders: %s".format(icyHeaders.toString()))
    }
    .setIcyMetadataChangeListener { icyMetadata ->
        Log.d("XXX", "onIcyMetaData: %s".format(icyMetadata.toString()))
    }
    .build()

// Produces DataSource instances through which media data is loaded
val dataSourceFactory = DefaultDataSourceFactory(applicationContext, null, icyHttpDataSourceFactory)

// The MediaSource represents the media to be played
val mediaSource = ExtractorMediaSource.Factory(dataSourceFactory)
    .setExtractorsFactory(DefaultExtractorsFactory())
    .createMediaSource(sourceUri)

// exoPlayer?.prepare(mediaSource) ...
  • Javadoc: Classes matching com.google.android.exoplayer2.ext.icy.* belong to this module.