ruben_ups
03/07/14, 02:59:01
Buenas noches.
La verdad que nunca habia creado un post en ninguna pagina, porque siempre intento buscarme la vida por mi cuenta hasta hoy xD.
Bueno de primeras, muchas gracias a todos por vuestro tiempo y ayuda.
Mi problema es que al abrir con el Navigation Drawer una actividad, no puedo hacer uso de los botones Play Stop definidos en el layout... Simplemente lo unico que consigo es que funcione el streaming sin hacer uso de los botones.. pero vaya eso no interesa..
(Ahora no funcionara el streaming porque he apagado el reproductor) pero lo podeis probar con cualquier otro.. por ejemplo este http://www.codigofuenteya.com.ar/recursos/gato.mp3 )
Os pego un poco de cogido..
public class StreamingFragment extends Fragment {
public StreamingFragment(){}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.streaming, container, false);
return rootView;
}
static MediaPlayer mPlayer;
Button buttonPlay;
Button buttonStop;
String url = "http://78.129.190.50/listen.php?ip=78.129.190.50&port=39150";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
buttonPlay = (Button) findViewById(R.id.play);
buttonPlay.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mPlayer = new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUS IC);
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) {
// TODO Auto-generated method stub
if(mPlayer!=null && mPlayer.isPlaying()){
mPlayer.stop();
}
}
});
}
protected void onDestroy() {
super.onDestroy();
// TODO Auto-generated method stub
if (mPlayer != null) {
mPlayer.release();
mPlayer = null;
}
}
}
:gracias:
La verdad que nunca habia creado un post en ninguna pagina, porque siempre intento buscarme la vida por mi cuenta hasta hoy xD.
Bueno de primeras, muchas gracias a todos por vuestro tiempo y ayuda.
Mi problema es que al abrir con el Navigation Drawer una actividad, no puedo hacer uso de los botones Play Stop definidos en el layout... Simplemente lo unico que consigo es que funcione el streaming sin hacer uso de los botones.. pero vaya eso no interesa..
(Ahora no funcionara el streaming porque he apagado el reproductor) pero lo podeis probar con cualquier otro.. por ejemplo este http://www.codigofuenteya.com.ar/recursos/gato.mp3 )
Os pego un poco de cogido..
public class StreamingFragment extends Fragment {
public StreamingFragment(){}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.streaming, container, false);
return rootView;
}
static MediaPlayer mPlayer;
Button buttonPlay;
Button buttonStop;
String url = "http://78.129.190.50/listen.php?ip=78.129.190.50&port=39150";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
buttonPlay = (Button) findViewById(R.id.play);
buttonPlay.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mPlayer = new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUS IC);
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) {
// TODO Auto-generated method stub
if(mPlayer!=null && mPlayer.isPlaying()){
mPlayer.stop();
}
}
});
}
protected void onDestroy() {
super.onDestroy();
// TODO Auto-generated method stub
if (mPlayer != null) {
mPlayer.release();
mPlayer = null;
}
}
}
:gracias: