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 Roywise · Jul 23, 2018 at 02:49 PM · audioclipwebrequest

UnityWebRequestMultimedia to get AudioClip from API

What I'm trying to accomplish sounds fairly easy. I try to download an AudioClip from our own API using an UnityWebRequestMultimedia but the AudioClip which it retrieves seems to be null all the time.

This is the IEnumerator that runs in a Coroutine to load the AudioClip:

 private static IEnumerator loadAudio(DownloadJob<AudioClip> job)
 {
     UnityWebRequest webRequest = UnityWebRequestMultimedia.GetAudioClip(job.URL, AudioType.MPEG);
     
     yield return webRequest.SendWebRequest();
 
     if (!webRequest.isNetworkError && !webRequest.isHttpError)
     {
         DownloadHandlerAudioClip dlHandler = (DownloadHandlerAudioClip)webRequest.downloadHandler;
         if(dlHandler.isDone)
         {
             AudioClip audioClip = dlHandler.audioClip;
             
             if(audioClip != null)
             {
                 _audioCacheManager.Add(job.Key, audioClip);
                 job.Done(audioClip);
             }
             else
             {
                 job.Failed("Retrieved AudioClip is null.");
             }
         }
         else
         {
             job.Failed("The download process is not completely finished.");
         }
     }
     else
     {
         job.Failed(webRequest.error);
     }
 }


I can't spot any issues with this piece of code and I suspect that the WebRequest does not follow the API's redirect that points it to the audio file directly even though the RedirectLimit has not been changed and should still be on the default value of 32. When the call URL is opened in the browser it'll show an audioplayer without problems.

Any ideas?

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

2 Replies

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

Answer by Roywise · Jul 24, 2018 at 11:49 AM

Apparently the WebRequest did get the correct data but Unity does not allow the use of DownloadHandlerAudioClip.audioClip when the audiofile is MP3 format because of the patent ( https://feedback.unity3d.com/suggestions/streaming-mp3-support-now-that-patent-has-expired ).

To work around this I took the raw data ( DataHandlerAudioClip.data ) and used an external library to convert it to WAV data and created an AudioClip with that. ( https://gamedev.stackexchange.com/questions/114885/how-do-i-play-mp3-files-in-unity-standalone )

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
avatar image
0

Answer by RukiPomidory · Feb 25, 2021 at 06:33 PM

if someone still has trouble with it - just upgrade your project to unity 2020.1.14f1 I am not sure, when exactly it was fixed, but in 2020.1.14 loading clip from mp3 is not a problem.

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

88 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 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 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 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

A method for streaming custom audio from the hard drive 0 Answers

Usage of DownloadHandlerAudioClip.streamAudio 1 Answer

How can I load an AudioClip from a local audio file using UnityWebRequests? 1 Answer

How to use Unity Web request Multimedia to download FLAC audio File and convert it to audio clip? 2 Answers

How to get audioclip from UnityWebRequest 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