Transmita y descargue audio desde la URL

I am developing app that search for song and able play and download music/song.I used this url http://tinysong.com/Phdj , this is redirecting to music web page and there its playing song. i used below code to play song.

    //play music
    MediaPlayer mMediaPlayer = new MediaPlayer();
    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    try{
         mMediaPlayer.setDataSource("http://tinysong.com/Phdj");
            mMediaPlayer.prepareAsync();
                }catch(IOException e){
        e.printStackTrace();
        }
        catch (IllegalArgumentException e){
                e.printStackTrace();    
                }catch (IllegalStateException e){
                e.printStackTrace();
            mMediaPlayer.setOnPreparedListener(new   MediaPlayer.OnPreparedListener() 
                            {

                                @Override
                                public void onPrepared(MediaPlayer mp) 
                                {
                                    mp.start();
                                }
                            });

ERROR: 09-21 11:26:49.674: I/MediaPlayer(6735): setLPAflag() in 09-21 11:26:49.674: I/MediaPlayer(6735): mContext is null, can't getMirrorDisplayStatus!!! 09-21 11:26:49.674: I/MediaPlayer(6735): setLPAflag() out 09-21 11:26:58.693: E/MediaPlayer(6735): error (1, -2147483648) 09-21 11:26:58.693: E/MediaPlayer(6735): Error (1,-2147483648)

Is AndroidMedia Library play only .mp3 format? Can i play music from above Url?How can i do that?

preguntado el 21 de septiembre de 13 a las 07:09

1 Respuestas

You have not passed the context in setDataSource()

Prueba esta

String path="http://tinysong.com/Phdj";

    Uri myUri = Uri.parse(path);

            MediaPlayer mp = new MediaPlayer();
            try {

                mp.setDataSource(this, myUri);
                mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
                mp.setOnPreparedListener(new OnPreparedListener() {

                    @Override
                    public void onPrepared(MediaPlayer mp) {

                        mp.start();
                        // TODO Auto-generated method stub

                    }
                });
                mp.prepareAsync();
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (SecurityException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

Respondido el 21 de Septiembre de 13 a las 13:09

getting this error: 09-21 17:35:50.315: E/MediaPlayer(30342): java.io.FileNotFoundException: No content provider: tinysong.com/Phdj 09-21 17:35:58.293: E/MediaPlayer(30342): error (1, -2147483648) 09-21 17:35:58.333: E/MediaPlayer(30342): Error (1,-2147483648) - brinda k

Have you create the reference to the MediaPlayer ? - Anchit Mittal

Sorry am new to media player...what that reference to media player? - brinda k

09-21 17:35:50.315: E/MediaPlayer(30342): java.io.FileNotFoundException: No content provider: tinysong.com/Phdj 09-21 17:35:58.293: E/MediaPlayer(30342): error (1, -2147483648) 09-21 17:35:58.333: E/MediaPlayer(30342): Error (1,-2147483648) - brinda k

is media player only supports .mp3 file? can you please check that url and confirm me that url is good to use for media players? - brinda k

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.