Log in or register to post comments

Enable audio source if video is not playing

October 3, 2016 - 1:51pm #1

Hi,

I can´t figure out this: when my app see the trigger, I play a background sound, with an Audio source component in my ImageTarget.

When I lost the trigger image in the cam, that same sound stops. So far so good. I control this from the script DefaultTrackableEventHandler.cs (code below)

Now, I add a video with a soundtrack, so I have two sounds at the same time: the background and the video sound, but I want to have only one at any specific time: either the video is playing (in which case I want to stop all audio sources in the app), or the video is paused (and the audio sources get enabled again).

I may be wrong here, but I suspect I have to control the app sounds from VideoPlaybackBehaviour.cs (if I detect the video is playing, turn off all the other Audio sources of the app, and visceversa). I was trying to accomplish this, but with no sucess until now...

 

If somebody have any idea on how to accomplish this, I´d be very thankful!

 

Thank you very much!

 

        private void OnTrackingFound()

        {

            Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);

            Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);

            // Enable rendering:

            foreach (Renderer component in rendererComponents)

            {

                component.enabled = true;

            }

   //REPRODUCIR AUDIO DEL TRACTOR CUANDO DETECTAMOS LA IMAGEN DE TRACKING (EL TRIGGER)

   AudioSource[] audioComponents = GetComponentsInChildren<AudioSource>();

   foreach (AudioSource component in audioComponents) {

    component.GetComponent<AudioSource>().Play();

   }

.....

        private void OnTrackingLost()

        {

            Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);

            Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);

            // Disable rendering:

            foreach (Renderer component in rendererComponents)

            {

                component.enabled = false;

            }

   //PARAR AUDIO DEL TRACTOR CUANDO PERDEMOS LA IMAGEN DE TRACKING (EL TRIGGER)

   AudioSource[] audioComponents = GetComponentsInChildren<AudioSource>();

   foreach (AudioSource component in audioComponents) {

    component.GetComponent<AudioSource>().Pause();

   }



            

Log in or register to post comments