Android Open Source - androidify-yourself Android Sound Player






From Project

Back to project page androidify-yourself.

License

The source code is released under:

MIT License

If you think the Android project androidify-yourself listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.github.androidify;
/*  w w w  . j a  v  a 2  s .  co m*/

import android.media.MediaPlayer;
import android.os.Environment;
import android.util.Log;

import java.io.IOException;

public class AndroidSoundPlayer {

    private final String fileName;
    private MediaPlayer mediaPlayer = null;

    public AndroidSoundPlayer(String fileName) {
        this.fileName = Environment.getExternalStorageDirectory().
                getAbsolutePath() + "/" + fileName;
    }

    public void startPlaying() {
        if (mediaPlayer != null) stopPlaying();

        mediaPlayer = new MediaPlayer();
        try {
            mediaPlayer.setDataSource(fileName);
            mediaPlayer.prepare();
            mediaPlayer.start();
        } catch (IOException e) {
            Log.e("SoundPlayer", "prepare() failed");
        }
    }

    public void stopPlaying() {
        if (mediaPlayer == null) return;
        mediaPlayer.release();
        mediaPlayer = null;
    }

    public boolean isPlaying() {
        return mediaPlayer != null && mediaPlayer.isPlaying();
    }
}




Java Source Code List

com.github.androidify.AndroidDrawables.java
com.github.androidify.AndroidSoundPlayer.java
com.github.androidify.AndroidSoundRecorder.java
com.github.androidify.AndroidifyViewPagerAdapter.java
com.github.androidify.AndroidifyViewPagerItemFragment.java
com.github.androidify.BitmapUtils.java
com.github.androidify.MainActivity.java
com.github.androidify.PlaceholderFragment.java