Audio stream?

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Audio stream?

Postby escaper » Thu Aug 05, 2010 11:46 pm

Hello guys,

First thanks for all those tutorials!

I am starting to build my first app(hello world doesnt count :roll:).
So the idea is an mp3 or aac streaming player, the problem is i do not know how to start.
Done some research but all of the solutions are for old android sdk(1.5)...

Does MediaPlayer have some ability to stream from a url and then play it?

Thanks!
escaper
Freshman
Freshman
 
Posts: 2
Joined: Thu Aug 05, 2010 11:32 pm

Top

Re: Audio stream?

Postby jonbonazza » Fri Aug 06, 2010 12:46 am

What's wrong with using stuff from android 1.5? That jusst means it would be backwards compatible.

If a method has been deprecated, then you can see a plausible replacement for the method on the android documentation.
jonbonazza
Master Developer
Master Developer
 
Posts: 665
Joined: Thu Jul 15, 2010 2:58 pm
Location: WV USA

Re: Audio stream?

Postby escaper » Fri Aug 06, 2010 4:18 pm

Done something, which of course doesn't work.
Code: MediaPlayer mPlayer = new MediaPlayer();
mPlayer.setDataSource("http://blablablah");
mPlayer.prepare();
mPlayer.start();

Error on second and third line: Unhandled exception type IOException.
Google says, Note: Also, IllegalArgumentException and IOException either need to be caught or passed on when using setDataSource(), since the file you are referencing may not exist.

Excellent Google documentation, which tells you nothing.:)
escaper
Freshman
Freshman
 
Posts: 2
Joined: Thu Aug 05, 2010 11:32 pm

Re: Audio stream?

Postby jonbonazza » Fri Aug 06, 2010 5:07 pm

You need to put it in a try/catch block like so:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. try{
  2.      mPlayer.setDataSource("blah blah blah");
  3.      mPlayer.prepare();
  4.      mPlayer.start();
  5. }catch(Exception e)
  6. {
  7.      //handle exceptions here...
  8. }
  9.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
jonbonazza
Master Developer
Master Developer
 
Posts: 665
Joined: Thu Jul 15, 2010 2:58 pm
Location: WV USA

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 4 guests