OSDN Git Service

Use MediaPlayer instead of VoicePlayer.
authorAtsuo Igarashi <atsuoigarashi@gmail.com>
Wed, 6 Apr 2011 08:49:03 +0000 (17:49 +0900)
committerAtsuo Igarashi <atsuoigarashi@gmail.com>
Wed, 6 Apr 2011 08:49:03 +0000 (17:49 +0900)
Signed-off-by: Atsuo Igarashi <atsuoigarashi@gmail.com>
src/jp/androidgroup/nyartoolkit/ARToolkitDrawer.java
src/jp/androidgroup/nyartoolkit/NyARToolkitAndroidActivity.java
src/jp/androidgroup/nyartoolkit/model/VoicePlayer.java [deleted file]

index acf59a6..f7642b2 100644 (file)
@@ -39,6 +39,7 @@ package jp.androidgroup.nyartoolkit;
 
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
+import android.media.MediaPlayer;
 import android.os.SystemClock;
 import android.util.Log;
 
@@ -47,8 +48,6 @@ import java.util.ArrayList;
 
 import min3d.core.Renderer;
 
-import jp.androidgroup.nyartoolkit.model.VoicePlayer;
-
 import jp.nyatla.nyartoolkit.NyARException;
 import jp.nyatla.nyartoolkit.core.NyARCode;
 import jp.nyatla.nyartoolkit.core.param.NyARParam;
@@ -118,7 +117,7 @@ public class ARToolkitDrawer
        // Renderer of min3d
     private Renderer mRenderer;
 
-       private VoicePlayer mVoiceSound = null;
+       private MediaPlayer mMediaPlayer = null;
 
        static {
                System.loadLibrary("yuv420sp2rgb");
@@ -197,10 +196,10 @@ public class ARToolkitDrawer
 
        /**
         *
-        * @param mVoiceSound
+        * @param mediaplayer
         */
-       public void setVoicePlayer(VoicePlayer mVoiceSound) {
-               this.mVoiceSound = mVoiceSound;
+       public void setMediaPlayer(MediaPlayer mediaplayer) {
+               this.mMediaPlayer = mediaplayer;
        }
 
        /**
@@ -268,12 +267,17 @@ public class ARToolkitDrawer
                                }
                        }
                        mRenderer.objectPointChanged(found_markers, ar_code_index, resultf, cameraRHf);
-                       if(mVoiceSound != null)
-                               mVoiceSound.startVoice();
+                       if (mMediaPlayer != null) {
+                               if (!mMediaPlayer.isPlaying())
+                                       mMediaPlayer.start();
+                       }
                } else {
                        Log.d("AR draw", "not exist marker.");
-                       if(mVoiceSound != null)
-                               mVoiceSound.stopVoice();
+                       if (mMediaPlayer != null) {
+                               if (mMediaPlayer.isPlaying())
+                                       mMediaPlayer.pause();
+                       }
+
                        mRenderer.objectClear();
                }
 
index 1a7f142..2e54323 100644 (file)
@@ -64,6 +64,7 @@ import android.graphics.Matrix;
 import android.graphics.PixelFormat;
 import android.hardware.Camera;
 import android.hardware.Camera.PreviewCallback;
+import android.media.MediaPlayer;
 import android.opengl.GLSurfaceView;
 import android.os.Build;
 import android.os.Bundle;
@@ -129,6 +130,7 @@ public class NyARToolkitAndroidActivity extends Activity implements View.OnClick
 
        private ARToolkitDrawer arToolkitDrawer = null;
 
+       private MediaPlayer mMediaPlayer = null;
 
        /** This Handler is used to post message back onto the main thread of the application */
        private class MainHandler extends Handler {
@@ -359,10 +361,14 @@ public class NyARToolkitAndroidActivity extends Activity implements View.OnClick
                        patt.add(getResources().openRawResource(R.raw.pattkanji));
                        arToolkitDrawer = new ARToolkitDrawer(camePara, width, patt, mRenderer);
 
-                       //TODO init VoicePlayer for ARToolkit.
-//                     VoicePlayer mVoiceSound = new VoicePlayer();
-//                     mVoiceSound.initVoice(getResources().openRawResourceFd(R.raw.xxx_voice));
-//                     arToolkitDrawer.setVoicePlayer(mVoiceSound);
+
+//                     mMediaPlayer = MediaPlayer.create(this, R.raw.miku_voice);
+//                     mMediaPlayer.setLooping(true);
+//             mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
+//                 public void onPrepared(MediaPlayer mediaplayer) {
+//                             arToolkitDrawer.setMediaPlayer(mediaplayer);
+//                 }
+//             });
        }
 
                FrameLayout frame = (FrameLayout) findViewById(R.id.frame);
@@ -379,6 +385,10 @@ public class NyARToolkitAndroidActivity extends Activity implements View.OnClick
         frame.removeView(mGLSurfaceView);
         mGLSurfaceView = null;
 
+        if (mMediaPlayer != null)
+               mMediaPlayer.release();
+        mMediaPlayer = null;
+
         arToolkitDrawer = null;
     }
 
diff --git a/src/jp/androidgroup/nyartoolkit/model/VoicePlayer.java b/src/jp/androidgroup/nyartoolkit/model/VoicePlayer.java
deleted file mode 100644 (file)
index c078edc..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/* 
- * PROJECT: NyARToolkit for Android SDK
- * --------------------------------------------------------------------------------
- * This work is based on the original ARToolKit developed by
- *   Hirokazu Kato
- *   Mark Billinghurst
- *   HITLab, University of Washington, Seattle
- * http://www.hitl.washington.edu/artoolkit/
- *
- * NyARToolkit for Android SDK
- *   Copyright (C)2010 NyARToolkit for Android team
- *   Copyright (C)2010 R.Iizuka(nyatla)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- * 
- * For further information please contact.
- *  http://sourceforge.jp/projects/nyartoolkit-and/
- *  
- * This work is based on the NyARToolKit developed by
- *  R.Iizuka (nyatla)
- *    http://nyatla.jp/nyatoolkit/
- * 
- * contributor(s)
- *  noritsuna
- */
-
-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();
-               }
-       }
-
-}