Selection

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.

Iphone Apps Profit Formula

Iphone Apps Profit Formula

The Easy Formula To Making Money With Iphone Apps. The exemplary development of technology from then till now has helped everyone in all aspects of our lives. Essential factors including social, physical, mental, and the like have been touched by these mechanics making our existence so easier.

Get My Free Ebook


Post a comment