Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by renezuidhof · Mar 18, 2015 at 01:54 PM · ioswww classwav

Loading .wav on iOS with WWW

I am trying to load a .wav using the WWW class. This works fine on Windows (PC) and Android. But on my iPhone 4 the app freezes when calling the method below (it stays in the while loop).

Does someone have an idea about what is going wrong?

 private Track LoadTrack(string pathname)
 {
     WWW audioToLoadPath = new WWW("file://" + pathname);
 
     while (!audioToLoadPath.isDone) 
     {
         //Wait untill it's done
     }
         
     Track loadedAudio = Instantiate(TrackInstantiator) as Track;
     loadedAudio.GetAudioSource().clip = audioToLoadPath.GetAudioClip(true, false);
 
     return loadedAudio;
 }

The pathname i am passing is retrieved by something like this (simplified exampe):

 DirectoryInfo info = new DirectoryInfo(Application.persistentDataPath);
 string pathname = persistentInfo.GetDirectories ()[0].FullName;

Edit: The path put in the WWW class is: file:///var/mobile/Applications/APP_GUID/Documents/file3.wav

XCode is not giving me any hints/debug information about this. Also audioToLoadPath.error is empty.

Other things i have tried:

  • Remove 'File://'

  • Tried it with 'File://' and 'File:///'

  • Tried 'File://localhost/var/...'

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fafase · Mar 27, 2015 at 05:02 AM 0
Share

Is xCode saying anything? Also, you shouldn't need the "File://" since you are using persistentDataPath which already contains all you need to reach the folder.

avatar image renezuidhof · Mar 27, 2015 at 01:11 PM 0
Share

I'll check what xCode sais. When i remove 'File://' it doesn't work on Windows nor on Android. I'll give it a try on my iPhone, just to be sure...

avatar image renezuidhof · Mar 27, 2015 at 07:50 PM 0
Share

Removing 'File://' did not work :(

avatar image MakakWasTaken · Mar 29, 2015 at 11:30 PM 0
Share

Have you tried putting a yield return null; in the while area? I am not sure it is actually waiting for it to finish.

avatar image renezuidhof · Mar 29, 2015 at 11:35 PM 0
Share

I used to not have a timeout, but I have waited for atleast 10 seconds and still nothing happened. On android the files load almost directly, so I can't imagine it should take so much time on iOS

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by sumeeton · Mar 30, 2015 at 09:05 AM

You should always use coroutine when downloading files using WWW

 IEnumerator LoadTrack(string pathname)
  {
      WWW www = new WWW(System.IO.Path.Combine("file://", pathname);
      yield return www;
      if(www.error != null)
      {
           Debug.Log("Couldn't Load file");
      }
      else
      {
           Track loadedAudio = Instantiate(TrackInstantiator) as Track;
           loadedAudio.GetAudioSource().clip = www.GetAudioClip(true, false);
      }
  }
 
 
 
 // Start the loading using...
 StartCoroutine(LoadTrack(pathname));
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bonfire-Boy · Mar 30, 2015 at 11:53 AM 1
Share

Note that it's not just the use of a coroutine, it's also the yield return www that's important here. You don't need to explicitly "wait until it's done", the yield does that for you. There have been questions on this here before, suggesting that this is more critical on iOS than other platforms.

avatar image renezuidhof · Mar 30, 2015 at 01:19 PM 0
Share

Thanks! I will try this and will post here how it went.

avatar image renezuidhof · Mar 31, 2015 at 08:10 PM 0
Share

It worked! Thank you very much!! I am starting to like couroutines more and more :)

One small thing: System.IO.Path.Combine("file://", pathname), does not work if 'pathname' is an absolute path (like C:/Documents/file.wav). It won't be a problem on Android or iOS but it was on Windows. Besides that, the code you send worked with almost no changes.

avatar image TheKingOfTheRoad · Aug 07, 2015 at 08:40 PM 0
Share

hello, what is "Track"?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is there a way to fix uploadprogress on mobile? 1 Answer

Ios problem with www class 2 Answers

Trying to load and play saved .wav from /Documents iOS 2 Answers

WWW yield is not returning any value in ios for yahoo finance api 2 Answers

how to load textures bigger than size limit through WWW? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges