Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.media.MediaPlayer; public class Main { private static MediaPlayer mediaPlayer; public static void playAudio(Context context, int resId) { if (context == null) throw new NullPointerException("context cannot be null"); mediaPlayer = MediaPlayer.create(context, resId); mediaPlayer.start(); mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mp.release(); } }); } }