Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Media Player Url specific issue

I am working in one of my android project in which I am playing sound with media player. When I use this URL for playing song I get some IOException as follow but song is playing fine in MediaPlayer. What should be the problem?

public void startMediaPlayer(String url) {

    Log.e("urlToPlay==>",url);
    // start new song for play

    if(mediaPlayer==null){
        mediaPlayer=new MediaPlayer();
    }else{
        mediaPlayer.reset();
    }
    Uri myUri1 = Uri.parse(url);

    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    try {

        mediaPlayer.setDataSource(getActivity(), myUri1);
        mediaPlayer.prepareAsync();

        mediaPlayer.setOnPreparedListener(new OnPreparedListener() {

            @Override
            public void onPrepared(MediaPlayer player) {
                playPause=true;
                player.start();
                mediaFileLengthInMilliseconds = player.getDuration(); // gets the song length in milliseconds from URL

            } 
        });

        mediaPlayer.setOnCompletionListener(new OnCompletionListener() {

            @Override
            public void onCompletion(MediaPlayer mp) {
                playPause=false;
           }
        });

        mediaPlayer.setOnErrorListener(new OnErrorListener() {

            @Override
            public boolean onError(MediaPlayer arg0, int arg1, int arg2) {

                Log.e("onError==>","Something went wrong"+arg1+"");
                Log.e("onError==>","Something went wrong"+arg2+"");
                return false;
            }
        });

    } catch (IllegalArgumentException e) {
        e.printStackTrace();
        mediaPlayer.release();
    } catch (SecurityException e) {
        e.printStackTrace();
        mediaPlayer.release();
    } catch (IllegalStateException e) {
        e.printStackTrace();
        mediaPlayer.release();
    } catch (IOException e) {
        e.printStackTrace();
        mediaPlayer.release();
    }
}

I got following exception while playing the file

06-01 15:30:24.758: D/MediaPlayer(12450): setDataSource IOException happend : 
06-01 15:30:24.758: D/MediaPlayer(12450): java.io.FileNotFoundException:  No content provider: http://pleer.com/browser-extension/files/72338325d4W.mp3
06-01 15:30:24.758: D/MediaPlayer(12450):   at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1053)
06-01 15:30:24.758: D/MediaPlayer(12450):   at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:907)
06-01 15:30:24.758: D/MediaPlayer(12450):   at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:834)
06-01 15:30:24.758: D/MediaPlayer(12450):   at android.media.MediaPlayer.setDataSource(MediaPlayer.java:969)
06-01 15:30:24.758: D/MediaPlayer(12450):   at android.media.MediaPlayer.setDataSource(MediaPlayer.java:923)
06-01 15:30:24.758: D/MediaPlayer(12450):   at com.hyper.musicapp.fragments.SearchFragmentMusic.startMediaPlayer(SearchFragmentMusic.java:998)
06-01 15:30:24.758: D/MediaPlayer(12450):   at com.hyper.musicapp.fragments.SearchFragmentMusic$SearchSoundCloudTrackAdapter$1.onClick(SearchFragmentMusic.java:473)
06-01 15:30:24.758: D/MediaPlayer(12450):   at android.view.View.performClick(View.java:4639)
06-01 15:30:24.758: D/MediaPlayer(12450):   at android.view.View$PerformClick.run(View.java:19252)
06-01 15:30:24.758: D/MediaPlayer(12450):   at android.os.Handler.handleCallback(Handler.java:733)
06-01 15:30:24.758: D/MediaPlayer(12450):   at android.os.Handler.dispatchMessage(Handler.java:95)
06-01 15:30:24.758: D/MediaPlayer(12450):   at android.os.Looper.loop(Looper.java:146)
06-01 15:30:24.758: D/MediaPlayer(12450):   at android.app.ActivityThread.main(ActivityThread.java:5511)
06-01 15:30:24.758: D/MediaPlayer(12450):   at java.lang.reflect.Method.invokeNative(Native Method)
06-01 15:30:24.758: D/MediaPlayer(12450):   at java.lang.reflect.Method.invoke(Method.java:515)
06-01 15:30:24.758: D/MediaPlayer(12450):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
06-01 15:30:24.758: D/MediaPlayer(12450):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
06-01 15:30:24.758: D/MediaPlayer(12450):   at dalvik.system.NativeStart.main(Native Method)
06-01 15:30:24.758: D/MediaPlayer(12450): Couldn't open file on client side, trying server side
like image 576
Hitesh Kamani Avatar asked Nov 01 '22 03:11

Hitesh Kamani


1 Answers

Try to add the url scheme like "file://" or "http://". worked for me when i got the same exception trying to play a local file.

like image 140
dy_ Avatar answered Nov 11 '22 10:11

dy_