Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

AudioClip instantiate, why is this working in Editor but NOT on iOS build???

Discussion in 'iOS and tvOS' started by SuperTalesNat, Aug 16, 2013.

  1. SuperTalesNat

    SuperTalesNat

    Joined:
    Mar 20, 2013
    Posts:
    18
    ANY help or guidance would be GREATLY appreciated.

    I have an issue where this code runs flawlessly on Editor, but for some reason fails on iOS. The audio clip is even assigned on iOS, but doesn't play as it does in the editor at runtime.

    I'm loading an AssetBundle thats formatted as iPhone type that has multiple MP3 files in it. Those are then instantiated at runtime, and hooked up to multiple AudioSources in my scene.

    Is there something i'm doing wrong that iOS just doesnt like? These same commands are working fine for other file types in the same AssetBundle (hooking up textures and atlases).

    Code that i'm using is below.

    Thanks in advance for ANY help or suggestions people may have.

    Code (csharp):
    1.  
    2.  
    3.     public string[] soundName;
    4.     public AudioSource[] soundSource;
    5.  
    6.     IEnumerator DownloadBundle()
    7.     {
    8.        
    9.         //commence download of bundle.
    10.         d = WWW.LoadFromCacheOrDownload (atlasBundlePath_ios, 1);      
    11.         yield return d;
    12.        
    13.         //any error messages are here.
    14.         if(d.error!=null) Debug.Log(d.error);
    15.  
    16.         foreach(string sn in soundName){
    17.             d.assetBundle.Load(sn);
    18.             AudioClip soundInstance = Instantiate(d.assetBundle.Load (sn)) as AudioClip;
    19.             soundInstance.name = sn;
    20.             foreach(AudioSource asource in soundSource){
    21.                 if (sn == asource.name) {
    22.                     asource.clip = soundInstance;
    23.                     Debug.Log (asource.name + " is now hooked up with " + asource.clip.name);
    24.                 }
    25.             }
    26.         }
    27.     }
    28.  
    29.  
     
  2. SeanPDawson

    SeanPDawson

    Joined:
    Jul 25, 2013
    Posts:
    2
    We are having the exact same problem with pretty much the same code as you with minor differences. Did you end up solving this problem?