Skip to content

Latest commit

 

History

History
104 lines (77 loc) · 4.16 KB

README.md

File metadata and controls

104 lines (77 loc) · 4.16 KB

DEPRECATED / MERGED UPSTREAM

This 3rd-party extension moved into ExoPlayer 2.10 directly (see the 2.10 release announcement). It remains functional but you might want to port to the official version as I won't continue to maintain this library any further.

Usage

With ExoPlayer 2.10, fetching shoutcast metadata is straightforward:

// ... exoPlayer instance already created

exoPlayer?.addMetadataOutput {
    for (i in 0 until it.length()) {
        val entry = it.get(i)
        if (entry is IcyHeaders) {
            Log.debug("onMetadata: IcyHeaders $entry")
        }
        if (entry is IcyInfo) {
            Log.debug("onMetadata: IcyInfo $entry")
        }
    }
}

// The MediaSource represents the media to be played
val mediaSource = ProgressiveMediaSource
    .Factory(DefaultDataSourceFactory(applicationContext, userAgent))
    .createMediaSource(sourceUri)

// exoPlayer?.prepare(mediaSource) ...

ExoPlayer2 Shoutcast Metadata Protocol (ICY) extension

Download License Build Status

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:

Usage

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) ...

Download

implementation 'saschpe.android:exoplayer2-ext-icy:2.1.0'

Snapshots of the development version are available in Sonatype's snapshots repository.

License

Copyright 2018 Sascha Peilicke

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.