Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Xan1995 · Aug 05, 2016 at 10:53 AM · audiostreamingassetsmemory usageaudioclip www load

Streaming music from StreamingAssets folder

Hi all I have problem with streaming music from StreamingAssets folder. I need this for custom player soundtracks. It takes much memory.

I did some testing (10 ogg files - total 61,3MB) of uncompressed loading and streaming.

Table ("Empty" means empty project with no audio and "Inside" means audio files inside Assets folder) Memory is changing when streaming around +- 20MB

Streaming from StreamingAssets (what I need) takes such memory. And there is another problem which other not have. When streaming music 1, play next music and then play music 1 again, it is not playing! Only silence.

I storing clips on array of AudioClip called clips. Here is my loading code

 IEnumerator LoadAllClips(bool streaming)
 {
 //... more code
 
 // Request to our file on HDD
 WWW request = new WWW("file:///" + filePath);
 yield return StartCoroutine(WaitForRequest(request));
 
 // Get audio clip and rename it
 AudioClip clip = request.GetAudioClip(true, streaming);
 clip.name = fileName;
 
 // Add to array
 clips[i] = clip;
 
 // ... more code
 }

I can store only file paths and doing WWW requests runtime. But it will be more work and more complicated. Is there a better way?

(btw: forum gives me "Your content can not be submitted. error")

table.png (7.9 kB)
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
2

Answer by Xan1995 · Aug 09, 2016 at 05:27 PM

No reply? Unity community is well...

I found solution but it is complicated. I store only paths to files in array and doing WWW request before play required clip. (storing WWW requests not helped)

Music Player

 void Play(string fileName)
 {
     // Unload audio clip
     if (myAudioSource.clip != null)
     {
         myAudioSource.Stop();
         AudioClip clip = myAudioSource.clip;
         myAudioSource.clip = null;
         clip.UnloadAudioData();
         DestroyImmediate(clip, false); // This is important to avoid memory leak
     }
 
     // Load Clip then assign to audio source and play
     manager.LoadClip(fileName, (clip) => { myAudioSource.clip = clip; myAudioSource.Play(); });
 }

Music Manager

 public void LoadClip(string fileName, Action<AudioClip> onLoadingCompleted)
 {
     StartCoroutine(LoadClipCoroutine("file:///" + fileName, onLoadingCompleted));
 }
 
 IEnumerator LoadClipCoroutine(string file, Action<AudioClip> onLoadingCompleted)
 {
     WWW request = new WWW(file);
     yield return request;
 
     if (onLoadingCompleted != null)
         onLoadingCompleted(request.GetAudioClip(true, true));
 
     request.Dispose();
 }

If anybody have better solution, please let me know.

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Stream audio from a YouTube playlist's URL? 0 Answers

VideoPlayer: No audio when playing from StreamingAssets 1 Answer

UnityWebRequestMultimedia.GetAudioClip dont't work in WebGL build (2019.3.15f1). 1 Answer

How would I go about using music from StreamingAssets folder (imported by the player) 0 Answers

How can I load an AudioClip from a local audio file using UnityWebRequests? 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