androidandroid-music-playerinternet-radio

Play a radio station in Android Application


How can I play a radio station using Media Player in Android?

I am using an iRadeo station that has two songs with the

   url:"https://www.iradeo.com/station/133063" 

but when I try to do

   Uri myUri = Uri.parse("https://www.iradeo.com/station/133063"); 

the Media Player throws an error saying java.io.FileNotFoundException: No content provider

But when I try to play a specific song from this station by using .../.../station/133063/download-track/469508 as my new uri, the Media Player works and the application begins to play the song.

Does anyone know why I can't play the whole playlist using the iRadeo radio station url? Thanks!


Solution

  • Your link points to a HTML page, and MediaPlayer can't play it because it's not a music file. Although you can play songs when you open that page in browser, MediaPlayer doesn't know that. So you must point to actual song files on server and then play them one after other.

    And how do you do that? I guess you don't know what songs will be there in advance. If you do, just use links to that files, like the one you posted and skip this paragraph. If you don't, thing can be tricky.
    Unless iRadeo has public API for stuff like this, I don't think there is easy solution.
    But there is a bit hacky and not so easy way: since you have list of songs and links to download next to them, you extract those links from HTML page. General way to do it is like this: find where list of songs is on the page and for every item in the list find the download button and use its link. I can't help you much more. And be aware - any change of site's implementation could break your code.

    Once you have files location, it's time to play them. You can find how to do it here: https://stackoverflow.com/a/14548795/2078587. Just use URIs intead of raw files.

    PS. I'm not great at explaining stuff. If you don't understand anything, feel free to ask.