1、在packages/apps/Gallery2/AndroidManifest.xml文件中增加

<uses-permission android:name="android.permission.CAMERA" />

2、packages/apps/Gallery2/src/com/mediatek/gallery3d/util/PermissionHelper.java

--- a/alps/packages/apps/Gallery2/src/com/mediatek/gallery3d/util/PermissionHelper.java

+++ b/alps/packages/apps/Gallery2/src/com/mediatek/gallery3d/util/PermissionHelper.java

@@ -83,6 +83,7 @@ public class PermissionHelper {

         // get permissions needed in current scenario

         ArrayList<String> permissionsNeeded = new ArrayList<String>();

         permissionsNeeded.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);

+ permissionsNeeded.add(Manifest.permission.CAMERA);

         Uri uri = activity.getIntent().getData();

         if (uri != null && uri.toString().startsWith("content://mms")) {

             permissionsNeeded.add(Manifest.permission.READ_SMS);

 

3、修改packages/apps/Gallery2/src/com/android/gallery3d/app/MovieActivity.java

import com.mediatek.gallery3d.video.IMovieListLoader.LoaderListener;

 import com.mediatek.gallery3d.video.DefaultMovieListLoader;

 import android.os.PowerManager;

+import android.hardware.Camera;

+import android.graphics.YuvImage;

+import java.io.ByteArrayOutputStream;

+import android.graphics.Matrix;

+import android.media.FaceDetector;

+import android.graphics.Canvas;

+import android.graphics.BitmapFactory;

+import android.graphics.Rect;

+import android.graphics.Paint;

+

+import android.hardware.Camera;

+import android.hardware.Camera.Face;

+import android.hardware.Camera.FaceDetectionListener;

+import android.content.pm.PackageManager;



 /**

  * This activity plays a video from a specified URI.

@@ -95,7 +109,7 @@ import android.os.PowerManager;

  * to set the action bar logo so the playback process looks more seamlessly integrated with

  * the original activity.

  */

-public class MovieActivity extends Activity implements LoaderListener , CreateBeamUrisCallback {

+public class MovieActivity extends Activity implements LoaderListener , CreateBeamUrisCallback , FaceDetectionListener {

     @SuppressWarnings("unused")

     private static final String TAG = "Gallery2/MovieActivity";

     public static final String KEY_LOGO_BITMAP = "logo-bitmap";

@@ -165,8 +179,9 @@ public class MovieActivity extends Activity implements LoaderListener , CreateBe

     private final Runnable mPlayVideoRunnable = new Runnable() {

         @Override

         public void run() {

+ Log.i("chengrq", "mBeamVideoIsPlaying:" + mBeamVideoIsPlaying);

             if (mPlayer != null && mBeamVideoIsPlaying) {

-                Log.i(TAG, "NFC call play video");

+                Log.i("chengrq", "NFC call play video");

                 mPlayer.onPlayPause();

             }

         }

@@ -513,6 +528,12 @@ public class MovieActivity extends Activity implements LoaderListener , CreateBe

             Log.v(TAG, "onPause, no permission, directly return");

             return;

         }

+

+ if(mCameraDevice != null){

+ stopFaceDetection();

+ mCameraDevice.stopPreview();

+ mCameraDevice.release();

+ }



         mResumed = false;

         if (mControlResumed && mPlayer != null) {

@@ -557,7 +578,71 @@ public class MovieActivity extends Activity implements LoaderListener , CreateBe

         //}@

         enhanceActionBar();

         mMovieHooker.onResume();



+ //chengrq start 

+ try {

+ Log.i("chengrq", "open camera");

+ mCameraDevice = android.hardware.Camera.open(1);

+ if (mCameraDevice != null) {

+ android.util.Log.e("chengrq","open camera successful");

+ }

+ } catch (Exception e) {

+            mCameraDevice = null;

+ }

+

+ if(mCameraDevice != null){

+ mCameraDevice.startPreview();         //该语句可放在回调后面,当执行到这里,调用前面的setPreviewCallback 

+

+ startFaceDetection();

+ }

+ //end

     }

+

+ private void startFaceDetection(){

+ if(mCameraDevice != null){

+ mCameraDevice.setFaceDetectionListener(this);

+ mCameraDevice.startFaceDetection();

+ }

+ }

+

+ private void stopFaceDetection(){

+ if(mCameraDevice != null){

+ mCameraDevice.setFaceDetectionListener(null);

+ mCameraDevice.stopFaceDetection();

+ }

+ }

+

+ @Override

+ public void onFaceDetection(Face[] faces, Camera arg1) {

+ // TODO Auto-generated method stub

+ //Log.e("chengrq","onFaceDetection");

+ if(faces != null){

+ if(faces.length > 0 && mHandler != null){

+ mHandler.removeCallbacks(mPauseVideoRunnable);

+ if(!mPlayer.isPlaying()){

+ mPlayer.onPlayPause();

+ }

+ }else{

+ if(mPlayer.isPlaying()){

+ mHandler.postDelayed(mPauseVideoRunnable, 500);

+ }

+ }

+ }

+ }

+

+ private android.hardware.Camera mCameraDevice;



     @Override

     public void onWindowFocusChanged(boolean hasFocus

 

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐