play Audio using MediaPlayer - Android Media

Android examples for Media:Audio

Description

play Audio using MediaPlayer

Demo Code


//package com.java2s;
import java.io.File;

import java.io.IOException;

import android.app.Activity;

import android.media.MediaPlayer;

public class Main {
    @Deprecated// w ww  . j  ava2 s .c  o  m
    public static void playAudio(final Activity activity, final File file)
            throws IOException {
        MediaPlayer mp = new MediaPlayer();
        mp.setDataSource(file.getAbsolutePath());
        try {
            mp.prepare();
            mp.start();
        } catch (IllegalStateException e) {
            mp.release();
        }
    }
}

Related Tutorials