Skip to content

Instantly share code, notes, and snippets.

@wavecos
Last active March 1, 2016 03:36
Show Gist options
  • Save wavecos/b32d4dd36615934ee04c to your computer and use it in GitHub Desktop.
Save wavecos/b32d4dd36615934ee04c to your computer and use it in GitHub Desktop.
public class DetailActivity extends AppCompatActivity implements MediaPlayer.OnPreparedListener
...
private MediaPlayer mediaPlayer;
...
// Setup MediaPlayer
mediaPlayer = new MediaPlayer();
mediaPlayer.setOnPreparedListener(this);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource(REPLACE_WITH_SOME_URL_RESOURCE);
mediaPlayer.prepareAsync();
} catch (IOException e) {
e.printStackTrace();
Log.e(TAG, e.getLocalizedMessage());
}
.
.
.
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment