Java tutorial
//package com.java2s; import android.media.MediaPlayer; import java.io.IOException; public class Main { private static MediaPlayer mediaPlayer; private static boolean isPlaying = false; public static void play(String filePath) { if (isPlaying) return; if (mediaPlayer == null) { mediaPlayer = new MediaPlayer(); } mediaPlayer.reset(); try { mediaPlayer.setDataSource(filePath); mediaPlayer.prepare(); mediaPlayer.start(); isPlaying = true; } catch (IOException e) { e.printStackTrace(); } } }