Reproducción de transmisiones de radio por Internet en Android: la transmisión se detiene después de 20 a 30 minutos

I am using the MediaPlayer object in an Android application to play Shoutcast Internet Radio Streams but facing problem in playing the streams for longer durations

The problem is that MediaPlayer suddenly stops playing stream after say 20-30 minutes. No error is captured in the MediaPlayer listeners. After doing a lot of search in various forums, this seems to be a problem with the phone going to sleep mode

  1. But, how do I know when does the phone goes to sleep?
  2. I have read somewhere, that the MediaPlayer needs to acquire a Wake Lock so that CPU does not go to sleep ever. Is that the problem? And if yes,how do I acquire a Wake Lock?
  3. The problem seems to be more when listening over WiFi. Is there some Wake Lock required on WiFi as well?

I have been struggling for quite a long now. Can anybody help please?

preguntado el 10 de marzo de 12 a las 09:03

1 Respuestas

Agregar a Manifest.xml:

<uses-permission android:name="android.permission.DEVICE_POWER"></uses-permission>

In your class where you playing stream:

PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
wl.acquire();        
{       
    // Your code here   
    // in this block CPU Will not go to the sleep mode   
} 
wl.release();

Más información aquí http://developer.android.com/reference/android/os/PowerManager.html

respondido 10 mar '12, 15:03

That could be reason? Also, how to apply WiFi Lock? - user669231

Yes, it's a reason. I think there no locks only for wi-fi. You can lock only CPU, Screen bright, Key bright. - XXX

Also you can use Bound Service for long-standing connection. More information here desarrollador.android.com/guide/topics/fundamentals/services.html - XXX

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.