Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android mediaplayer get playing url

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?

like image 510
Maria Gheorghe Avatar asked Mar 05 '15 17:03

Maria Gheorghe


People also ask

Where is the MediaPlayer on Android 13?

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.

How do I play audio files on Android?

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.

Which method of the MediaPlayer class allows you to read a music file from a given point in time?

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.

How do I turn off MediaPlayer on Android?

The feature is as simple as tapping and holding on the media card of any app then choosing Dismiss.


1 Answers

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
like image 148
Amrut Bidri Avatar answered Sep 28 '22 04:09

Amrut Bidri