эй, я работаю над простым аудио-плеером. Приложение в Android. в этом приложении, я просто хочу играть звуковой файл из Интернета мой код выглядит следующим образом:Начало с Android-плеером Android
static MediaPlayer mPlayer;
Button buttonPlay;
Button buttonStop;
String url = "http://android.programmerguru.com/wp-content/uploads/2013/04/hosannatelugu.mp3";
@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_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();
Toast.makeText(getApplicationContext(), "Preparing!", Toast.LENGTH_LONG).show();
Log.i("info","Preparing!");
} 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();
}
Toast.makeText(getApplicationContext(), "Prepared!", Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "Size="+(mPlayer.getDuration()/100)+" isPlaying="+mPlayer.isPlaying()+" isLooping="+mPlayer.isLooping(), Toast.LENGTH_LONG).show();
Log.i("info","Prepared!");
mPlayer.start();
Toast.makeText(getApplicationContext(), "Size="+(mPlayer.getDuration()/100)+" isPlaying="+mPlayer.isPlaying()+" isLooping="+mPlayer.isLooping(), Toast.LENGTH_LONG).show();
}
});
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;
}
}
public void onCompletion(MediaPlayer mp) {
Toast.makeText(getApplicationContext(), "Completed", Toast.LENGTH_LONG).show();
}
все работает плавно, но музыка не начинает
Добавить –
Я получаю тост, который говорит, что музыка не играет –
@ Дайте! я уже указал –