Streaming Large mp3s: prepare() or prepareAsync()?

All your problems with Audio, Video and Images.

Streaming Large mp3s: prepare() or prepareAsync()?

Postby fredley » Sun Apr 18, 2010 8:09 pm

I'm building an app that needs to stream large mp3s, such as the one found here. This seems to work, but very temperamentally if I use code like the following:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. play.setOnClickListener(new View.OnClickListener() {
  2.             public void onClick(View v) {
  3.                 // Perform action on click
  4.                 try {
  5.                                         player.setDataSource(mediaLoc); //String of URL of mp3 file
  6.                         player.prepare();
  7.                         player.start();
  8.                                 } catch (IllegalArgumentException e) {
  9.                                 ...
  10.                                 }
  11.               }
  12. });
  13.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4

This sometimes works, sometimes gets stuck buffering. It's useless anyway, as I need a single MediaPlayer object across my app, which I can get from a singleton:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. play.setOnClickListener(new View.OnClickListener() {
  2.             public void onClick(View v) {
  3.                 // Perform action on click
  4.                         if(playing)
  5.                         {
  6.                                 mp.togglePlayPause(); //mp is the MediaPlayer extended class from singleton
  7.                                 if(mp.isPlaying()){
  8.                                         play.setImageResource(R.drawable.pause_icon);
  9.                                 }else{
  10.                                 play.setImageResource(R.drawable.play_icon);
  11.                                 }
  12.                         }else{
  13.                                         mp.play(context,mediaLoc);
  14.                                         playing = true;
  15.                                         state.setNowPlaying(jsonLoc);
  16.                                         state.setPlaying(true);
  17.                                         play.setImageResource(R.drawable.pause_icon);
  18.                         }
  19.                        
  20.             }
  21.         });
  22.  
  23. MediaPlayerExtended:
  24. ...
  25. public void play(Context contextIn,String input){
  26.                 context=contextIn;
  27.                 try {
  28.                         mp.reset();
  29.                         mp.setDataSource(input);
  30.                         mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
  31.                         mp.prepare();
  32.                         mp.start();
  33.                         ...
  34.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4

This doesn't work, despite being the same thing, and it doesn't work using prepareAsync() with the proper call backs ever. Am I doing something completely wrong?
fredley
Freshman
Freshman
 
Posts: 6
Joined: Fri Apr 16, 2010 8:04 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Exabot [Bot] and 16 guests