Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

How to have a video's audio play only on image target recognition?

Discussion in 'AR' started by hashmm2, Feb 6, 2020.

  1. hashmm2

    hashmm2

    Joined:
    Oct 21, 2019
    Posts:
    16
    So I currently have an image target that brings up a video when it's detected. The issue I'm currently facing is that the connected audio starts playing on the Scene's activation. I haven't been able to figure out how to have the audio play only when the image target is detected.

    Any ideas?
     
  2. Alexis-Dev

    Alexis-Dev

    Joined:
    Apr 16, 2019
    Posts:
    121
    Hello,

    To do that, I instantiate a prefab with audio (or video) when the image is tracking.
    By the way, I use ARFoundation.

    Best,
    Alexis
     
    hashmm2 likes this.
  3. jalajshah

    jalajshah

    Joined:
    Mar 5, 2018
    Posts:
    60
    for this issue , check ImageTarget example in AR Foundation sample.

    create copy of TrackedImageInfoManager.cs or modify as per requirement.


    you can edit void UpdateInfo(ARTrackedImage trackedImage) Line :60

    and add condition like this


    Code (CSharp):
    1. if (trackedImage.trackingState != TrackingState.tracking)
    2.   {
    3.       if(trackedImage.referenceImage.name == "ABC"){
    4.     if(!isPlaying){
    5. //Play video
    6. }}}
    7. else{
    8. // stop video
    9. }
    10.  
    11.  
     
    hashmm2 likes this.
  4. hashmm2

    hashmm2

    Joined:
    Oct 21, 2019
    Posts:
    16
    Thank you @Alexis-Dev and @jalajshah. I did something similar to jalajshah's solution, I was using Vuforia so I went into a similar script and made the required changes in there.
     
  5. philspitlerSF

    philspitlerSF

    Joined:
    Oct 10, 2018
    Posts:
    37
    Hi guys, I am looking to do the same thing but do not see TrackedImageInfoManager.cs

    I do see ARTrackedImageManger.cs but I don't see anything in there to do with the tacking state.

    Any advice?

    Thanks

    Phil