Log in or register to post comments

How to resume the audio when the target re-found?

November 16, 2011 - 6:58pm #1

Hello, Genius!!

I just start to use Unity3d for AR, and i would like to use sound file(mp3, wav .etc) for my 'teapot' as well.

1. I set AudioListener to ImageTargetChips.
2. I added a sudio file(Audio Source) to ImageTargetChips.
3. I un-checked 'play on awake' and wrote 'audio.Play()' to 'TrackableEventHandler/OnTackingFound()' , so that it will be played when the target detected.
4. and I wrote 'audio.Pause()' to 'TrackableEventHandler/OnTackingLost()'

so It worked well 'til the sound Pause.
I mean when my app find target, the sound file played. and if it lost target the sound stopped.

HOWEVER, when my app find the target AGANE, the audio file play AGAIN from the top. :eek:
I wish the audio file RESUME when the target found again...

How could i do that?? is there any solution for that??

How to resume the audio when the target re-found?

October 23, 2015 - 1:09pm #6

How i specifies the audio that i want?

How to resume the audio when the target re-found?

August 11, 2014 - 8:54pm #5

Thank you for this cap10subtext

To the Vuforia Tech Support team, perhaps something like this can be included in future releases.

Re: How to resume the audio when the target re-found?

April 25, 2012 - 1:55pm #4

This is what I've written into DefaultTrackableEventHandler.cs. It pauses and resumes all Audio sources added to the ImageTargets children so they don't restart.

    #region PRIVATE_METHODS


    private void OnTrackingFound()
    {
        Renderer[] rendererComponents = GetComponentsInChildren<Renderer>();

        // Enable rendering:
        foreach (Renderer component in rendererComponents) {
            component.enabled = true;
        }
		
		AudioSource[] audioComponents = GetComponentsInChildren<AudioSource>();
		foreach (AudioSource component in audioComponents) {
			component.audio.Play();
			
			}

        Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
    }


    private void OnTrackingLost()
    {
        Renderer[] rendererComponents = GetComponentsInChildren<Renderer>();

        // Disable rendering:
        foreach (Renderer component in rendererComponents) {
            component.enabled = false;
        }
		AudioSource[] audioComponents = GetComponentsInChildren<AudioSource>();
		foreach (AudioSource component in audioComponents) {
			component.audio.Pause();
			}

        Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
    }

Re: How to resume the audio when the target re-found?

January 27, 2012 - 3:57am #3

UP - Please

Re: How to resume the audio when the target re-found?

November 17, 2011 - 8:45am #2

I don't have any experience with Unity and pausing/resuming sound playback. Maybe someone else in the community can help? Or this might be a better question for the Unity forums.

If you find that you can get this to work without QCAR (e.g. on a button press) but are still having trouble getting it to work in response to Trackable events let us know.

- Kim

Log in or register to post comments