Last active
October 5, 2015 13:21
-
-
Save smamran/5c7e61cc6dce812cac3f to your computer and use it in GitHub Desktop.
API Guides Media Playback
This file contains hidden or 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
| MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.sound_file_1); | |
| mediaPlayer.start(); // no need to call prepare; create() does that for you | |
| Uri myUri = ....; // initialize Uri here | |
| MediaPlayer mediaPlayer = new MediaPlayer(); | |
| mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); | |
| mediaPlayer.setDataSource(getApplicationContext(), myUri); | |
| mediaPlayer.prepare(); | |
| mediaPlayer.start(); | |
| // Playing from a remote URL via HTTP streaming looks like this | |
| String url = "http://.........."; // Your URL here | |
| MediaPlayer mediaPlayer = new MediaPlayer(); | |
| mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); | |
| mediaPlayer.setDataSource(url); | |
| mediaPlayer.prepare(); // might take long! (for buffering, etc) | |
| // mediaPlayer.prepareAsync() // preparing the media in the background | |
| mediaPlayer.start(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment