Play streaming Internet Radio

Hi all,

I’m trying to make an app that will play streaming audio from a radio station.

I have these URL’s for the stream, but can’t get any of them to load / play:

http://streamer4.xmc.se/retro-mp3
http://streamer4.xmc.se/retro64 (AAC)
http://streamer4.xmc.se/retro48 (AAC)

Just need to get one of them to work.

This is what I have tried:

gameMusic = audio.loadStream( “http://streamer4.xmc.se/retro-mp3” )
gameMusicChannel = audio.play(gameMusic, {channel=1, loops=-1})

Works fine with a local MP3 fil, but when I use the URL for the stream, I get this message in the Output:

WARNING: Cannot create path for resource file 'http://streamer4.xmc.se/retro-mp3
’ b/c it does not exist.

WARNING: Failed to create audio sound(http://streamer4.xmc.se/retro-mp3)
Any ideas?? Thanks :slight_smile:

Michael
Denmark [import]uid: 220014 topic_id: 35447 reply_id: 335447[/import]

Sounds stupid but try to play it as remote video:
http://docs.coronalabs.com/api/library/media/playVideo.html
or download it first:
http://docs.coronalabs.com/api/library/network/download.html
and play from local directory on complete. [import]uid: 12704 topic_id: 35447 reply_id: 140894[/import]

Thanks for the input… Did not work for me though :frowning: (Using PlayVideo)

I don’t make much sense to try and down load a live stream from a radio station, since it is playing 24/7.

Any other ideas?

Michael
[import]uid: 220014 topic_id: 35447 reply_id: 140945[/import]

audio.loadStream() loads a large local audio clip and does not load URLs.

@gtatarkin is correct. media.playVideo() is the right API call to play streaming video.

[import]uid: 199310 topic_id: 35447 reply_id: 140978[/import]

I suspect there may be some confusion on the use of the metaphor “stream”. On low level computer terminology streaming audio means to simply open the file and start playing it before the whole file finishes loading.

Then there are streaming services where you access a web server and play a contentious stream over the internet.

Our audio.loadStream() is for the first use, load a large local file (not a URL) and play it before it fully loads to avoid having your app pause while it loads.

Our media.playVideo() is for playing video an and that’s why its named as it is. It’s designed to play video either from a local file or from an Internet URL in a streaming fashion (open file and start playing while it finishes loading). It is not intended for audio, but some people have manged to play audio from Internet URL’s using it.

Now for the URL’s in the OP, for some reason media.loadVideo() is not finding the URL. We are looking at this a bit closer to find out why.

[import]uid: 199310 topic_id: 35447 reply_id: 141138[/import]

I was able to play the stream using the following code:

[blockcode]
local function onComplete(event)
print(“stream complete”)
end

media.playVideo(“http://streamer4.xmc.se/retro64”, media.RemoteSource, true, onComplete )[/blockcode]

The documentation for media.RemoteSource could be a bit better and I’ll ask that it be clarified. [import]uid: 199237 topic_id: 35447 reply_id: 141287[/import]

Thanks to all!

I’m gonne give Perry’s example a go :slight_smile:

Michael
[import]uid: 220014 topic_id: 35447 reply_id: 141501[/import]

Sounds stupid but try to play it as remote video:
http://docs.coronalabs.com/api/library/media/playVideo.html
or download it first:
http://docs.coronalabs.com/api/library/network/download.html
and play from local directory on complete. [import]uid: 12704 topic_id: 35447 reply_id: 140894[/import]

Thanks for the input… Did not work for me though :frowning: (Using PlayVideo)

I don’t make much sense to try and down load a live stream from a radio station, since it is playing 24/7.

Any other ideas?

Michael
[import]uid: 220014 topic_id: 35447 reply_id: 140945[/import]

audio.loadStream() loads a large local audio clip and does not load URLs.

@gtatarkin is correct. media.playVideo() is the right API call to play streaming video.

[import]uid: 199310 topic_id: 35447 reply_id: 140978[/import]

I suspect there may be some confusion on the use of the metaphor “stream”. On low level computer terminology streaming audio means to simply open the file and start playing it before the whole file finishes loading.

Then there are streaming services where you access a web server and play a contentious stream over the internet.

Our audio.loadStream() is for the first use, load a large local file (not a URL) and play it before it fully loads to avoid having your app pause while it loads.

Our media.playVideo() is for playing video an and that’s why its named as it is. It’s designed to play video either from a local file or from an Internet URL in a streaming fashion (open file and start playing while it finishes loading). It is not intended for audio, but some people have manged to play audio from Internet URL’s using it.

Now for the URL’s in the OP, for some reason media.loadVideo() is not finding the URL. We are looking at this a bit closer to find out why.

[import]uid: 199310 topic_id: 35447 reply_id: 141138[/import]

I was able to play the stream using the following code:

[blockcode]
local function onComplete(event)
print(“stream complete”)
end

media.playVideo(“http://streamer4.xmc.se/retro64”, media.RemoteSource, true, onComplete )[/blockcode]

The documentation for media.RemoteSource could be a bit better and I’ll ask that it be clarified. [import]uid: 199237 topic_id: 35447 reply_id: 141287[/import]

Thanks to all!

I’m gonne give Perry’s example a go :slight_smile:

Michael
[import]uid: 220014 topic_id: 35447 reply_id: 141501[/import]

I have a question regarding this:

I was able to stream a file with the videoplayer but the problem is as soon as the app goes into suspended mode the audio doesn’t play anymore.

I put this into my build.settings without any success:

            UIBackgroundModes = {
                “audio”
            },

any ideas how to solve this problem?

Corona SDK isn’t designed for running in the background like that so there are no guarantees that it will work or will work in the future. 

Hey Rob,

thanks for your answer ( also here: http://forums.coronalabs.com/topic/34650-networkdownload-temporary-file-name/#entry179512 ). I manage to run music in suspended mode if it goes via media.loadstream(). I think it doesn’t work with the video stream method because apple doesn’t support this UIBackgroundModes feature for the video player.

You say Corona SDK isn’t designed for running in the background but as long as it works with media.loadstream() I don’t know why I shouldn’t use it.

So I tried to build a streaming service like you descriped on top of this page:

"streaming audio means to simply open the file and start playing it before the whole file finishes loading".

I tried that ( you answered in the other post as well ) but unfortunately it’s not as simple as that. I’ve read somewhere that normally a file to stream is split up in many .ts and one index file. The index file is more or less a seamingless playlist file that keeps the ts files together.

So I wondered: Is there maybe a chance that the file can be split while it’s downloaded?

And if a file is splitted, whould the media player be able to play these single parts that were ruffly cutted from let’s say a m4a file? It’s problably not that simple, right?

I have a question regarding this:

I was able to stream a file with the videoplayer but the problem is as soon as the app goes into suspended mode the audio doesn’t play anymore.

I put this into my build.settings without any success:

            UIBackgroundModes = {
                “audio”
            },

any ideas how to solve this problem?

Corona SDK isn’t designed for running in the background like that so there are no guarantees that it will work or will work in the future. 

Hey Rob,

thanks for your answer ( also here: http://forums.coronalabs.com/topic/34650-networkdownload-temporary-file-name/#entry179512 ). I manage to run music in suspended mode if it goes via media.loadstream(). I think it doesn’t work with the video stream method because apple doesn’t support this UIBackgroundModes feature for the video player.

You say Corona SDK isn’t designed for running in the background but as long as it works with media.loadstream() I don’t know why I shouldn’t use it.

So I tried to build a streaming service like you descriped on top of this page:

"streaming audio means to simply open the file and start playing it before the whole file finishes loading".

I tried that ( you answered in the other post as well ) but unfortunately it’s not as simple as that. I’ve read somewhere that normally a file to stream is split up in many .ts and one index file. The index file is more or less a seamingless playlist file that keeps the ts files together.

So I wondered: Is there maybe a chance that the file can be split while it’s downloaded?

And if a file is splitted, whould the media player be able to play these single parts that were ruffly cutted from let’s say a m4a file? It’s problably not that simple, right?

Hi!

Any news about playing audio files streamed from a remote url?

thx!