You now have a functioning, selectable list of radio stations! Of course, you don't do anything when an item is selected, so you'll have to do something about that. Thankfully, the ListView's tight integration with the ListActivity makes this a breeze. Simply override the protected method:

protectedvoid onListItemClick(

ListView l, View v, int position, long id)

StationData selectedStation = stationListVector.elementAt(position); MediaPlayer player = new MediaPlayer();

player.setDataSource(selectedStation.url); player.start();

catch (Exception e) {

Log.e("PlayerException", "SetData");

I've included the audio code that is, as far as I can tell, correct according to the documentation. Just because the documentation says that it works doesn't, however, mean that it actually will work. In fact, the previous code, which links to a Shoutcast MP3 link, doesn't throw an exception but doesn't play. I can only hope the Android engineers resolve this issue before the application launches.

There's been lively debate and lots of example code running around on the Web. A little work with Google's search engine will unfold the multitude of hacky workarounds.

Caution Nowhere in this example application have I done any useful error handling. Mostly I'll catch exceptions and print something to a log. Your eventual mobile app will have to be better about errors than I'm currently being, because, trust me, networking on the mobile can be a bit touch-and-go.

Easy Software Profits

Easy Software Profits

Here's How Anyone Can Start, Build and Run their Own Successful Software Empire Without Knowing the First Thing About Programming, Scripting Or Any 'Coder' Stuff. There is no doubt about it software sells. Software has a high percieved value and it solves problems for people.  A claim that can't always be made for PDF books, Video products and the like.

Get My Free Ebook

Post a comment