VoicePlayer.java :  » UnTagged » mobilebombsquad » jp » androidgroup » nyartoolkit » model » Android Open Source

Android Open Source » UnTagged » mobilebombsquad 
mobilebombsquad » jp » androidgroup » nyartoolkit » model » VoicePlayer.java
package jp.androidgroup.nyartoolkit.model;

import android.content.res.AssetFileDescriptor;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.util.Log;

/**
 * 
 * 
 * @author noritsuna
 *
 */
public class VoicePlayer {

    MediaPlayer mVoiceSound;
    
    public void initVoice(AssetFileDescriptor afd) {
        try {
          mVoiceSound = new MediaPlayer();

            mVoiceSound.setDataSource(afd.getFileDescriptor(),
                             afd.getStartOffset(),
                             afd.getLength());
            mVoiceSound.setLooping(true);

            if (mVoiceSound != null) {
              mVoiceSound.setAudioStreamType(AudioManager.STREAM_SYSTEM);
              mVoiceSound.prepare();
            }
          mVoiceSound.seekTo(0);
          mVoiceSound.start();
          mVoiceSound.pause();
        } catch (Exception ex) {
            Log.w("VoicePlayer", "Couldn't create click sound", ex);
        }
    }
    
    public void startVoice() {
      if(!mVoiceSound.isPlaying()) {
        mVoiceSound.start();
      }
    }
    public void stopVoice() {
      if(mVoiceSound.isPlaying()) {
        mVoiceSound.pause();
      }
    }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.