Note that there are some explanatory texts on larger screens.

plurals
  1. POStagefright media delay in 2.2 after setting data source?
    primarykey
    data
    text
    <p>My first post here. This website has been very useful for learning Android programming, thanks to everyone.</p> <p>I have a simple app that loads an MP3 stream and plays it. It works fine on 1.6 and 2.1 but on 2.2 it doesn't quite work right. It seems my service is having a problem starting, it's giving my an ANR and the dialog where I have to tap "Wait", and then finally the service starts. Why is the service taking a long time to start up?</p> <p>Here's my simple code that sets the source and plays the audio:</p> <pre><code> public class MyActivityService extends Service { MediaPlayer player = new MediaPlayer(); @Override public IBinder onBind(Intent intent) { return null; } @Override public void onCreate() { super.onCreate(); try { player.setDataSource("URL OF MUSIC FILE"); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { player.prepare(); player.setVolume(1, 1); player.setLooping(true); player.start(); Toast.makeText(getApplicationContext(), "Audio Service Started.", Toast.LENGTH_SHORT).show();} </code></pre> <p><strong>ADDENDUM:</strong></p> <p>Turns out it wasn't my service not starting, it's the audio that's not starting quickly enough in 2.2...</p> <p>I got rid of the ANRs when my service started and stopped by putting the <code>onCreate()</code> and <code>onDestroy()</code> methods of my service in their own threads, which is probably how it should have been from the beginning? Sorry, just learning.</p> <p>But the delay that's the real problem remains, to clarify --</p> <p>For example, my code, as it is right now, works fine and dandy and just how I want it to in 2.1 AND 2.2 when I set the data source to an MP3 file like this: <strong><a href="http://dl.dropbox.com/u/6916184/TestSongStream.mp3" rel="nofollow noreferrer">http://dl.dropbox.com/u/6916184/TestSongStream.mp3</a></strong></p> <p>BUT when I set the data source to an audio stream location like this: <strong><a href="http://d.liveatc.net/kjfk_twr" rel="nofollow noreferrer">http://d.liveatc.net/kjfk_twr</a></strong> or this: <strong><a href="http://relay.radioreference.com:80/192236577" rel="nofollow noreferrer">http://relay.radioreference.com:80/192236577</a></strong> it works correctly ONLY in 2.1. </p> <p>In 2.2 the sound does start playing eventually, but it takes "StagefrightPlayer" about 25 seconds or so after setting the data source until the audio starts as shown here:</p> <pre><code>07-31 02:54:30.176: INFO/StagefrightPlayer(34): setDataSource('http://relay.radioreference.com:80/192236577') 07-31 02:54:55.228: INFO/AwesomePlayer(34): calling prefetcher-&gt;prepare() 07-31 02:54:56.231: INFO/Prefetcher(34): [0x2cc28] cache below low water mark, filling cache. 07-31 02:54:56.337: INFO/AwesomePlayer(34): prefetcher is done preparing 07-31 02:54:56.347: DEBUG/AudioSink(34): bufferCount (4) is too small and increased to 12 07-31 02:54:57.337: ERROR/AwesomePlayer(34): Not sending buffering status because duration is unknown. </code></pre> <p>It also takes the same amount of time, about 25 seconds, to stop the media player after <code>player.stop()</code> is called in the <code>onDestroy()</code> method of my service, and the <code>onDestroy()</code> method continues on to Toast a message and cancel a notification.</p> <p>Is that just the way it is with 2.2? If so, I can work around the delays, that's not a problem. Or more likely is it something I am doing wrong? But it works exactly as I want in 1.6 and 2.1!</p> <p>Would posting more code help? </p> <p>My code is very simple. There are no audio controls or anything like that. Simply a start audio button and stop audio button that start and stop a service that plays an audio stream.</p> <p>Thank you for any help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload