Question

I am trying to implement a radio stream switcher in android. What I would like to do, in the desired order, is this:

  1. Start streaming a radio station
  2. Get the endTime of the current playing song from that station
  3. At endTime - Delta, I want to scan a list of stations and I want to get back a list of stations that have a new song starting in the interval [endTime, endTime + Delta']
  4. Switch to a stream from the result set in [3] and then repeat

So, I can stream a radio station (no problem). I can get a notification when the song changes (using streamscraper to fetch metadata and generate a notification when the metadata changes). However, what I have not been able to find out is whether it is possible to do the following:

  1. Get the endTime of the current playing song
  2. Scan a list of stations, and get songs that have started around the same time (so get startTime of songs) or songs that might be starting soon (if endTime of current song in those streams is near or if I can actually get the stream programme in advance).

If anyone could tell me whether this is possible, I would be obliged.

Was it helpful?

Solution

This isn't possible. You cannot know the end time of what is playing until it stops playing. The data just isn't there, and isn't even applicable to all streams. (Think of live programs, DJ-mixed shows, cross-fading start/end points, etc.)

OTHER TIPS

I was able to do something similar to what you are referring to with SHOUTcast. I am not sure how the log files for Icecast are formatted but I was able to use PHP to basically watch the logs for the "Song Change" event.

Once you are able to do so, you can execute code as needed. If you want to know the length of the title playing, you can start a timer when the song is updated and stop it once the song has changed again.

It's a bit tricky but it does work.. www.soundcheck.xyz - Automatically posts current playing song to Twitter in real time.

A stream consists of a seamless stream of mp3´s thats what a stream does...it stiches separate mp3´s to one large stream.

But theres track ID-tags in the stream...not shure if you can find end and start from them or if these start exactly at the track-start or other fixed positions.

Most stations dont send ahead info about the next track simply cause they dont know, most use auto-dj playlists where the server has to decide in the small break between old and new track what that new track will be ie: it dont decide on that while the old track is playing.

Some stations do send info (PHP to their webpages) what the next track will be but most dont...and if they do that info is ceretainly not in the stream itself.

Maybe a trick could be to add a delay for your listener
ie: what the listener is hearing currently
is old (up to a few minutes or 1 complete track)

Not shure how to create such delay...maybe you need to record (buffer) it
and play it back with a delay (in your app or via some additional server)

Your (not delayed) application will (hopefully) notice when the current song has ended
since a new one has started with a new ID2/3 tag...it will switch your listener to a new stream when his current but delayed song has ended.

Said different ...below the surface your application is looking ahead (relative to the listener)

You need to study the Shoutcast and ID-tag protocols. Additional silence-detection might help also (not foolproof).

May not always work..some stations dont send ID tags others crossfade their tracks (no silence)...exactly to avoid these tricks.

Or something like that...good luck i cant code anything..its just theory i suspect some shoutcast rippers to use this trick...i suppose they use this to scan multitple streams (in parallel) for certain preset artists-tracks. Maybe you can get some ideas by reverse-engineering those rippers. Since i have a radio myself i´m not a fan of these tricks since they steal from me while i pay for the rights....to many rippers will kill online radio.

In the end i dont see your idea (if i understand its purpose well) as usefull anyway
switching from one to another stream every next track dont seem like a enjoying experience.
Good radiostations will have a carefully made (ordered) playlist
if you mess that up your listener will get to much mood/style variations in a to short time.

The only usefull purpose for this is probably to build a automated ripper that can distract preset tracks/artist from a multitude of in parralel observed streams and record them when a wanted track is played...for many online stations those rippers are a big problem already, 10´s more of those rippers and online radio is dead...as result good quality and independent music wont be available anymore...and we will be stuck with only Youtube and other money infested conglomerates..i´m not looking forward to that....curious if you have an other usefull purpose.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top