Foros del Web » Programando para Internet » Android »

Reproductor streaming se reinicia al minimizar

Estas en el tema de Reproductor streaming se reinicia al minimizar en el foro de Android en Foros del Web. Que tal, soy novato en Android y pues ojala alguien me pueda ayudar con esto, y es que estoy armando una aplicacion para reproducir audio ...
  #1 (permalink)  
Antiguo 14/05/2014, 15:58
 
Fecha de Ingreso: octubre-2012
Mensajes: 45
Antigüedad: 11 años, 5 meses
Puntos: 0
Reproductor streaming se reinicia al minimizar

Que tal, soy novato en Android y pues ojala alguien me pueda ayudar con esto, y es que estoy armando una aplicacion para reproducir audio en streaming, exactamente para la transmision de una radio.

Ya tengo la aplicacion funcionando, (algunos detalles que faltan, pero minimos)... La instale y reproduce bien, carga bien...

Al darle click en "Play", reproduce el audio y además cambia la imagen del boton, la del play por el de stop, ahi todo va muy bien... Pero no se como indicarle al Activity sobre la reproducción, es decir, como detectar que la reproducción se está llevando a cabo por que el problema viene cuando minimizo la aplicacion, cuando vuelvo a abrirla me lanza al Activity inicial con el boton de play y no con el de stop. Y entonces, cuando le doy click al boton de play me vuelve a cargar el audio y se escucha DOBLE, y si vuelvo a minimizar la aplicacion hace lo mismo, pero ya con otra reproduccion nueva y es un caos!!

Entonces, me gustaria saber como indicar al Activity o al boton de play que detecte si ya se está reproduciendo, de ser así NO mostrar el boton de Play y en su lugar poner directamente el boton de Stop. O en su defecto, detener el audio cuando la aplicacion detecte que se ha iniciado nuevamente la aplicacion.



El codigo es este:

Código:
buttonPlay = (Button) findViewById(R.id.play);		
		buttonPlay.setOnClickListener(new OnClickListener() {

            
			public void onClick(View v) {
                
			
				buttonPlay.setVisibility(View.GONE);
				buttonStop.setVisibility(View.VISIBLE);

											
				mPlayer = new MediaPlayer();
				mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
				try {		
			        
					mPlayer.setDataSource(url);
				} catch (IllegalArgumentException e) {
					Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
				} catch (SecurityException e) {
					Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
				} catch (IllegalStateException e) {
					Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
				} catch (IOException e) {
					e.printStackTrace();
				}
				try {			        
					mPlayer.prepare();
				} catch (IllegalStateException e) {
					Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
				} catch (IOException e) {
					Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
				}
				mPlayer.start();
			}
		});
		
		buttonStop = (Button) findViewById(R.id.stop);
		buttonStop.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				buttonPlay.setVisibility(View.VISIBLE);
				buttonStop.setVisibility(View.GONE);
				// TODO Auto-generated method stub
				if(mPlayer!=null && mPlayer.isPlaying()){
					mPlayer.stop();
				}
			}
		});
	}


Alguna idea? Gracias....


.........
Cabe mencionar que la aplicacion tiene un problema publicado en este post, ojala alguien me pueda ayudar tambien en ese, pero ese es otro asunto...

http://www.forosdelweb.com/f165/forz...lipse-1099070/
.....

Etiquetas: app, minimizar, reproductor, streaming
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:30.