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. Dismiss Notice

Load audio file from iOS documents folder and play it

Discussion in 'Scripting' started by dev-vsemenchenko, Aug 16, 2015.

  1. dev-vsemenchenko

    dev-vsemenchenko

    Joined:
    May 18, 2015
    Posts:
    8
    Still can not achieve this. Can someone help me? I have file on device, I check it (I download it from network, from dropbox to my document directory). Then I am trying to play it and nothing happens. I need play mp3 and/or wav files. Here is how I am trying to play file:

    AudioClip clip1 = (AudioClip) Resources.Load(localFilePath); // localFilePath is path directly to file on device (full path, with "var" folder etc., with file extension)
    audioSource.clip = clip1;
    audioSource.Play();

    Also I try with PlayOneShot - not happens:( No errors or warnings and no sound.
    Thank you for helping!

    P.S. Duplicated from Audio thread because no one reply there.
     
  2. dev-vsemenchenko

    dev-vsemenchenko

    Joined:
    May 18, 2015
    Posts:
    8
    Finally fixed by myself. Maybe I help someone in future:

    publicIEnumeratorplayFile(stringpathToFile)
    {
    Debug.Log("Path to doc file = " + "file://" + pathToFile);

    WWWaudioLoader = newWWW("file://" + pathToFile);
    while( !audioLoader.isDone )
    yieldreturnnull;

    Debug.Log(audioLoader.GetAudioClip(false).name);
    audioSource.clip = audioLoader.GetAudioClip (false);
    audioSource.Play();
    }
     
  3. dev-vsemenchenko

    dev-vsemenchenko

    Joined:
    May 18, 2015
    Posts:
    8
    But very strange. It crashes on iOs device. Here is crash log:

    Maybe someone can help with this?