play resource Media - Android App

Android examples for App:Resource

Description

play resource Media

Demo Code


import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;

public class Main {
  public static MediaPlayer mMediaPlayer = null;

  public static void play(Context context, int id) {

    // MediaPlayer mMediaPlayer = new MediaPlayer();
    mMediaPlayer = MediaPlayer.create(context, id);
    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mMediaPlayer.setLooping(false);/*from w ww .j  a v  a  2  s . co  m*/
    mMediaPlayer.start();
  }
}

Related Tutorials