app/src/main/java/dev/appy/ar/android/arbook/main/MainActivity.java
/**
     * Registered with the Sceneform Scene object, this method is called at the start of each frame.
     *
     * @param frameTime - time since last frame.
     */
Registered with the Sceneform Scene object, this method is called at the start of each frame.
@param frameTime - time since last frame.
Registered with the Sceneform Scene object this method is called at the start of each frame . @param frameTime - time since last frame .
private void onUpdateFrame(FrameTime frameTime) {
        Frame frame = arFragment.getArSceneView().getArFrame();
        if (frame == null) {
            return;
        }
        Collection<AugmentedImage> updatedAugmentedImages = frame.getUpdatedTrackables(AugmentedImage.class);
        for (AugmentedImage augmentedImage : updatedAugmentedImages) {
            switch (augmentedImage.getTrackingState()) {
                case PAUSED:
                    viewPager.setVisibility(View.GONE);
                    break;
                case TRACKING:
                    fitToScanView.setVisibility(View.GONE);
                    tvHelp.setVisibility(View.GONE);
                    if (!augmentedImageMap.containsKey(augmentedImage)) {
                        AugmentedImageNode node = new AugmentedImageNode(this);
                        node.setImage(augmentedImage);
                        augmentedImageMap.put(augmentedImage, node);
                        arFragment.getArSceneView().getScene().addChild(node);
                        if (mp.isPlaying()) {
                            mp.stop();
                            mp.release();
                            mp = MediaPlayer.create(this, R.raw.raven);
                            mp.setLooping(true);
                        }
                        mp.start();
                        viewPager.animate()
                                .alpha(1f)
                                .setDuration(1200)
                                .start();
                        viewPager.setVisibility(View.VISIBLE);
                    }
                    break;
                case STOPPED:
                    augmentedImageMap.remove(augmentedImage);
                    break;
            }
        }
    }
private void onUpdateFrame ( FrameTime frameTime ) { Frame frame = arFragment . getArSceneView ( ) . getArFrame ( ) ; if ( frame == null ) { return ; } Collection < AugmentedImage > updatedAugmentedImages = frame . getUpdatedTrackables ( AugmentedImage . class ) ; for ( AugmentedImage augmentedImage : updatedAugmentedImages ) { switch ( augmentedImage . getTrackingState ( ) ) { case PAUSED : viewPager . setVisibility ( View . GONE ) ; break ; case TRACKING : fitToScanView . setVisibility ( View . GONE ) ; tvHelp . setVisibility ( View . GONE ) ; if ( ! augmentedImageMap . containsKey ( augmentedImage ) ) { AugmentedImageNode node = new AugmentedImageNode ( this ) ; node . setImage ( augmentedImage ) ; augmentedImageMap . put ( augmentedImage , node ) ; arFragment . getArSceneView ( ) . getScene ( ) . addChild ( node ) ; if ( mp . isPlaying ( ) ) { mp . stop ( ) ; mp . release ( ) ; mp = MediaPlayer . create ( this , R . raw . raven ) ; mp . setLooping ( true ) ; } mp . start ( ) ; viewPager . animate ( ) . alpha ( 1f ) . setDuration ( 1200 ) . start ( ) ; viewPager . setVisibility ( View . VISIBLE ) ; } break ; case STOPPED : augmentedImageMap . remove ( augmentedImage ) ; break ; } } }
Registered with the Sceneform Scene object, this method is called at the start of each frame.
Registered with the Sceneform Scene object this method is called at the start of each frame .
// When an image is in PAUSED state, but the camera is not PAUSED, it has been detected, // but not yet tracked. //String text = "Detected Image " + augmentedImage.getIndex(); //SnackbarHelper.getInstance().showMessage(this, text); // Have to switch to UI Thread to update View. //fitToScanView.setVisibility(View.GONE); // Create a new anchor for newly found images.