我有兴趣检索媒体播放器的当前网址或用户名。 如果我跑:
String url = "http://........"; // your URL here
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(url);
mediaPlayer.prepare(); // might take long! (for buffering, etc)
mediaPlayer.start();
有没有办法让这个媒体播放器运行的网址?
答案 0 :(得分:4)
class CustomMediaPlayer extends MediaPlayer
{
String dataSource;
@Override
public void setDataSource(String path) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException
{
// TODO Auto-generated method stub
super.setDataSource(path);
dataSource = path;
}
public String getDataSource()
{
return dataSource;
}
}
使用此CustomMediaPlayer类代替MediaPlayer获取传递给MediaPlayer的当前网址。
我希望此代码可以帮助您使用以下网址获取网址:
String url = "http://........"; // your URL here
CustomMediaPlayer customMediaPlayer = new CustomMediaPlayer ();
customMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
customMediaPlayer.setDataSource(url);
customMediaPlayer.prepare(); // might take long! (for buffering, etc)
customMediaPlayer.start();
String url1 = customMediaPlayer.getDataSource();// get your url here