0

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 !

Kanagalingam
  • 2,096
  • 5
  • 23
  • 40

2 Answers2

0

Your question is very abstract. Please add your unity and android activity code. What I think maybe the reason for this behavior is--when you click on the back button, your Android activity takes control back to unity where your video was playing and not rendering over target image to start the video. You may want to call that method again where your unity app read the target and started the video.

I found something related to your question. Please check answers to these question---> Can't pass back event from Unity to android library jar and How to return from Unity Player to previous running Android Activity?

NZT
  • 59
  • 5
0

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!

Kanagalingam
  • 2,096
  • 5
  • 23
  • 40