How to Play Web Address URL to Media Player in android?

白昼怎懂夜的黑 提交于 2019-12-13 22:18:22

问题


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 url that holds list of URLs then it is not playing in medi payer. Please tell me how can i resolve this issue ?


回答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;  
                 }  
            });  
       } 


来源:https://stackoverflow.com/questions/32284063/how-to-play-web-address-url-to-media-player-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!