Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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();
        }
    }
}