Skip to content Skip to sidebar Skip to footer

How To Play Web Address Url To Media Player In Android?

My URL contains number medial related URLs which we have to play in media player. When i am passing my any media url with extension .mp3 or .mp4. it plays but whn i am passing any

Solution 1:

this will help you:

private void PlayOnlineUrl() {  
            String url = "http://www.gaana.mp3"; // your URL here  
            MediaPlayer mediaPlayer = new MediaPlayer();  
            mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);  
            try {  
                 mediaPlayer.setDataSource(url);  
            } catch (IllegalArgumentException e) {  
                 e.printStackTrace();  
            } catch (SecurityException e) {  
                 e.printStackTrace();  
            } catch (IllegalStateException e) {  
                 e.printStackTrace();  
            } catch (IOException e) {  
                 e.printStackTrace();  
            }  
            mediaPlayer.prepareAsync();  
            // You can show progress dialog here untill it prepared to play  
            mediaPlayer.setOnPreparedListener(new OnPreparedListener() {  
                 @Override  
                 public void onPrepared(MediaPlayer mp) {  
                      // Now dismis progress dialog, Media palyer will start playing  
                      mp.start();  
                 }  
            });  
            mediaPlayer.setOnErrorListener(new OnErrorListener() {  
                 @Override  
                 public boolean onError(MediaPlayer mp, int what, int extra) {  
                      // dissmiss progress bar here. It will come here when  
                      // MediaPlayer  
                      // is not able to play file. You can show error message to user  
                      return false;  
                 }  
            });  
       } 

Post a Comment for "How To Play Web Address Url To Media Player In Android?"