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
1
Question by dansav · Mar 08, 2012 at 06:43 PM · iphonepathfoldermp3

How can I put a mp3 in the iphone documents folder then load it with www?

Is it possible to manually (or using some scripting) put a file in the iphone documents folder and call it up using the WWW protocol.

How do I put the file in? How do I get the path to the file?

Thanks, Dan

Comment
Add comment
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

1 Reply

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

Answer by mpavlinsky · Mar 08, 2012 at 07:26 PM

Certainly.

You can get a path to a writeable directory like so:

 string writeablePath = Application.dataPath.Substring(0, "/var/mobile/Applications/XXXXYYYY-XXXX-XXXX-XXXX-XXXXYYYYZZZZ/".Length) + "Documents/Raw";

Then you can use System.IO.Files to read and write the files in that directory:

 System.IO.File.WriteAllBytes(writeablePath + "/mydocument.mp3", bytes);
 byte[] mp3Bytes = System.IO.File.ReadAllBytes(writeablePath + "/mydocument.mp3");

And WWW:

 WWW mp3WWW = new WWW("file://" + writeablePath + "/mydocument.mp3");
 while (mp3WWW.isDone != true)
  {
     // Show progress or something.
     yield return null;
 }
 if (mp3WWW.error == null)
 {
     byte[] mp3Bytes = mp3WWW.bytes;
     // Do something cool.
 }
Comment
Add comment · Show 10 · 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 dansav · Mar 08, 2012 at 08:33 PM 0
Share

Thanks for the complete code examples. Where do I get the ID code for XXXXYYYY-XXXX-XXXX-XXXX-XXXXYYYYZZZZ?

avatar image mpavlinsky · Mar 08, 2012 at 08:54 PM 0
Share

It's already in Application.dataPath. I just put those as placeholder to show I wanted to keep that part of the string. I know how many digits and dashes there are, but I don't know exactly what they are since it's your app identifier or whatever. It could just as easily be (Application.dataPath.Substring(0, 62) + "Documents/Raw";) I just wanted to be a little more clear in my intent.

avatar image dansav · Mar 08, 2012 at 10:57 PM 0
Share

So the docs for datapath say //Data. So could I just stripoff my appname+".app/Data" from the entire string to get the right substring?

avatar image dansav · Mar 08, 2012 at 11:23 PM 0
Share

I'm getting the hang of it. I copied a file from my assets folder to the documents folder using just the system io commands. How do I let the user know the progress or whether it's completed or not. I know www has progress, and isDone but I can't use those. Right?

avatar image dansav · Mar 09, 2012 at 12:39 AM 0
Share

What's the recommended way to load the mp3 as an audio source clip. Should I use WWW? It says no strea$$anonymous$$g mp3 in the editor so I can't really test it in the editor. Is there an alternative way to load an audio clip using system io and assign it to the audio source. $$anonymous$$aybe like audio.clip=the path to the file? I can't use Resources.Load on the iphone right?

Show more comments

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

editor folder path on Mac 0 Answers

Saving current scene in another scene during gameplay? 1 Answer

Does DirectoryInfo GetFiles work on Android ? 2 Answers

How do I move the Asset Folder to another drive? 0 Answers

iPhone System.IO.File.Exists() not working 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