Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

unity 433 / 434 ios7 www.getaudioclip file:// right bytesize but NO ISREADYFORPLAYING

Discussion in 'Editor & General Support' started by concave, Mar 1, 2014.

  1. concave

    concave

    Joined:
    Aug 28, 2012
    Posts:
    48
    hi community!

    i have following problem killing my nervs. Iam on unity 4.3.3 or 4.3.4. (pro, android pro, ios pro)

    I' am using WWW www = new WWW(url); with an url like this: "file:// ... apppersistencelocation/filename.mp3"
    It gives the perfectly right length if i ask for www.bytesDownloaded and the same length like when i use
    "http:// ... some web server " for exactly the same testfile so iam sure that the download works.

    But afterwards when i use the method
    someAudioClip = www.GetAudioClip(false, false, AudioType.MPEG); on ios (7) (iphone4) the
    AudioClip never gets isReadyToPlay - true ON THE DEVICE when i read it from Filesystem with the file:// uri. (the http works)

    To clarify that there is no mistake in the code - it works perfectly in Editor switched to IOS platform and on Android Platform in Editor aswell as on the Device - on both platforms this should be supported on the Device refering to the Documentation.
    I am running it in a coroutine in a class that implements monobehaviour. the download brings the right bytelength and
    iam waiting for not null the audioclip is not null but while waiting for isReadyToPlay it never gets readytoplay.

    (i can share my code snipped but the steps are so straight forward and i allready tried different ways to implement it and it works on android and in the editor iam almost sure that its not the reason)

    if you had the same problem and found a solution. if you have a hint or a snipped that you are sure it works please support me before i go nuts. when you give it a try do you expierence the same problem?

    kind regards,
    concave
     
    Last edited: Mar 2, 2014
  2. G33RT

    G33RT

    Joined:
    Dec 27, 2013
    Posts:
    20
    I've just upgraded Unity to the latest version, and I am having exactly the same issues! Did anyone figure this out by now?

    Tnx,

    Geert
     
  3. Zergsbo

    Zergsbo

    Joined:
    Mar 21, 2014
    Posts:
    4
    I'm getting exactly the same problem with my tests on iOS. All the other platforms the AudioClip is loaded properly and the sound is played. On iOS I get no errors and the sound is empty but not null. I have ZERO channels and ZERO length. A very strange and disturbing problem. I opened a bug report to Unity. I'll wait for a bug fix or try another method to play sounds on the iOS. Did you guys find any workaround for this issue?

    Thanks!
     
  4. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    800
  5. Zergsbo

    Zergsbo

    Joined:
    Mar 21, 2014
    Posts:
    4
    I already filled a bug report of my own and I already voted on that specific issue on the tracker, let's hope they look into it, because it kind of stalls my "soon to be released" game. :(
     
  6. maspi

    maspi

    Joined:
    Feb 8, 2011
    Posts:
    18
    I am having exactly the same issues and posted a question but didn't get an answer. Great to know, that I'm not alone.
    So we have to wait for the next update.
     
  7. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,378
    wait a sec - this should be fixed in 4.5. Isnt it?
     
  8. AbandonedCart

    AbandonedCart

    Joined:
    Mar 4, 2014
    Posts:
    71
    Part of the problem may be calling file:// instead of file:///

    I wrote this snippet to play music from a "music" directory on the device and it is working perfectly:
    Code (CSharp):
    1. using System.IO;
    2.  
    3. private DirectoryInfo MusicFolder;
    4. private WWW musicFile;
    5. private string musicPath;
    6. public AudioSource musicPlayer;
    7.  
    8. private FileInfo[] musicList;
    9. private int track = 0;
    10. private int previousTrack = 0;
    11.  
    12. void Start()
    13. {
    14. #if UNITY_IPHONE || UNITY_EDITOR
    15.      musicPath = Application.persistentDataPath + "/music";
    16. #endif
    17. #if UNITY_ANDROID && !UNITY_EDITOR
    18.      musicPath = "/mnt/sdcard/Android/data/YOUR_PACKAGE_NAME/files/music";
    19. #endif
    20.      if (Directory.Exists(musicPath)) {
    21.           MusicFolder = new DirectoryInfo(musicPath);
    22.           musicList = MusicFolder.GetFiles();
    23.           if (musicPlayer && musicList.Length > 0) {
    24.                musicFile = new WWW("file:///" + musicList[track].FullName);
    25.                audio.clip = musicFile.GetAudioClip(false, false);
    26.           }
    27.      }
    28. }
    29.  
    30. void OnGui()
    31. {
    32.      if (track > 0) {
    33.           if (GUI.Button (new Rect (20, 20, 100, 40), "Previous"))
    34.           track = track - 1;
    35.      }
    36.      if (track < musicList.Length - 1) {
    37.           if (GUI.Button (new Rect (720, 20, 100, 40), "Next"))
    38.           track = track + 1;
    39.      }
    40.  
    41.      if (previousTrack != track) {
    42.           musicFile = new WWW("file:///" + musicList[track].FullName);
    43.           if (audio.isPlaying) {
    44.                musicPlayer.audio.Stop();
    45.           }
    46.           audio.clip = musicFile.GetAudioClip(false, false);
    47.           previousTrack = track;
    48.      }
    49. }
    50.  
    51. void Update()
    52. {
    53.      if (musicPlayer && musicList.Length > 0) {
    54.           if (audio.clip && !audio.isPlaying && audio.clip.isReadyToPlay) {
    55.                musicPlayer.audio.Play();
    56.           }
    57.      }
    58. }
    Don't forget to attach an AudioSource to the same GameObject and drag it to this script's AudioSource field in File Inspector.

    You could also use transform.gameObject.GetComponent<AudioSource>() in Awake() if you only have one AudioSource on the object.
     
  9. maspi

    maspi

    Joined:
    Feb 8, 2011
    Posts:
    18
    Interesting solution. Thank you.

    There was a bug (Playing Audio from HD on iOS) in R. 4.3 wich is solved in R. 4.5