Last active
April 24, 2016 23:57
-
-
Save omaraflak/4b842154471a3e7882c20a776990ac5c to your computer and use it in GitHub Desktop.
MediaPlayer Android from URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// DON'T FORGET IN MANIFEST: <uses-permission android:name="android.permission.INTERNET" /> | |
try { | |
MediaPlayer mediaPlayer = new MediaPlayer(); | |
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); | |
mediaPlayer.setDataSource("http://server.com/music.mp3"); | |
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { | |
@Override | |
public void onPrepared(MediaPlayer mp) { | |
mediaPlayer.start(); | |
} | |
}); | |
mediaPlayer.prepareAsync(); | |
} catch (Exception e) { | |
Log.e(TAG, e.getMessage()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment