Extracting metadata from Icecast stream using Exoplayer

后端 未结 5 1896
旧时难觅i
旧时难觅i 2021-01-07 02:31

Since switching from Mediaplayer to a simple implementation Exoplayer I have noticed much improved load times but I\'m wondering if there is any built in functionality such

5条回答
  •  灰色年华
    2021-01-07 03:29

    Parsing the Shoutcast Metadata Protocol consists of two parts:

    1. Telling the server that your client supports meta-data by sending the HTTP-Header Icy-Metadata:1, for example:

    curl -v -H "Icy-MetaData:1" http://ice1.somafm.com/defcon-128-mp3

    1. Parsing the meta-data from the stream

    Part one can be done without OkHttp based on ExoPlayer 2.6.1 (in Kotlin):

    // Custom HTTP data source factory with IceCast metadata HTTP header set
    val defaultHttpDataSourceFactory = DefaultHttpDataSourceFactory(userAgent, null)
    defaultHttpDataSourceFactory.setDefaultRequestProperty("Icy-MetaData", "1")
    
    // Produces DataSource instances through which media data is loaded.
    val dataSourceFactory = DefaultDataSourceFactory(
        applicationContext, null, defaultHttpDataSourceFactory)
    

    Part two is more involved and posting all the code is a little to much. You might want to take a look at the ExoPlayer2 extension I created instead:

    github.com/saschpe/android-exoplayer2-ext-icy

    It does not depend on OkHttp and is used in my Soma FM streaming radio application for Android called Alpha+ Player.

提交回复
热议问题