Search code examples
androidunity-game-engineaugmented-realityvuforia

Vuforia Video being played even if the image target is not focused


I have a project in which i used both Unity with Vuforia and Android studio

I am playing a Video whenever the ImageTarget is tracked and when the target is lost, video will be paused. I am using the same Vuforia Script for that.

I have a button in the Vuforia camera layer which sends me to the Android Activity on click.

When the image target is being focused (Video is playing now) and when i click on that button, Android acitvity is opened and when i resume back to UNITY SCENE from Android Activity, Video is not resuming playing until the image target is not focused. This functional flow is perfect!

But, When the image target is being focused (Video is playing now) and now i moves the camera away from Image Target (Video stops playing now) and when i click on the button, Android acitvity is opened and when i resume back to UNITY SCENE from Android Activity, Video playing is being resumed playing even if the image target is not focused !

So, i want to stop resuming of this video play whenever i resumes back to unity scene from Android activity and at the same time image target is not focused !

This is how i open Android Activity from Unity Scene,

AndroidJavaObject jo = new AndroidJavaObject("packagename.Activityname");
        int i = jo.Call<int>("openAndroidActivity");

Any help would be greatly appreciated !


Solution

  • After logging for hours, I found the solution. Just add the below piece of code in your onUpdate() method of your TrackableEventHandler.cs script.

      video = GetComponentInChildren<VideoPlaybackBehaviour>();
            if (mLostTracking == true && mHasBeenFound == false && video!=null && video.CurrentState == VideoPlayerHelper.MediaState.PLAYING)
            {
                video.VideoPlayer.Pause();
            }
    

    where video is defined as

    VideoPlaybackBehaviour video;

    globally..... Thanks!