I'm interested in retrieving the current url or uri of a Media Player. if i run :
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();
is there a way i get the url this media player is running?
A redesigned media player One of the more obvious upgrades you'll see on Android 13, is a redesigned media player widget. It shows up under Quick Settings and on the lock screen when media is playing.
Prepare media file: To play a media file, you need to first prepare it i.e. you need to load the file for playback. Methods used for doing this are prepare(), prepareAsync(), and setDataSource(). Start/Pause the playback: After loading the media file, you can start playing the media file by using the start() method.
pause(); On call to start() method, the music will start playing from the beginning. If this method is called again after the pause() method, the music would start playing from where it is left and not from the beginning.
The feature is as simple as tapping and holding on the media card of any app then choosing Dismiss.
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;
}
}
Use this CustomMediaPlayer class instead to MediaPlayer to get the current url that is passed to the MediaPlayer.
I hope this code might help you in getting the url using:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With