My URL contains number medial related URLs which we have to play in media player. When i am passing my any media url with extension .mp3 or .mp4. it plays but whn i am passing any url that holds list of URLs then it is not playing in medi payer. Please tell me how can i resolve this issue ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
this will help you:
private void PlayOnlineUrl() {
String url = "http://www.gaana.mp3"; // your URL here
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource(url);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
mediaPlayer.prepareAsync();
// You can show progress dialog here untill it prepared to play
mediaPlayer.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
// Now dismis progress dialog, Media palyer will start playing
mp.start();
}
});
mediaPlayer.setOnErrorListener(new OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
// dissmiss progress bar here. It will come here when
// MediaPlayer
// is not able to play file. You can show error message to user
return false;
}
});
}