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 /
  • Help Room /
avatar image
0
Question by Killercrush · Jan 26, 2016 at 11:18 PM · errorwwwaudioclip

Error without text

I'm trying to play sound file, downloaded with WWW class. Here is the code:

 using UnityEngine;
 using System.Collections;
 
 public class audio : MonoBehaviour
 {
     AudioSource source;
     // Use this for initialization
     void Start()
     {
         source = GetComponent<AudioSource>();
         StartCoroutine(StartAudio());
     }
 
     IEnumerator StartAudio()
     {
         WWW audioLoader = new WWW("file://E:/Music/sample.wav");
         AudioClip a_clip = audioLoader.audioClip;
 
         while (!a_clip.isReadyToPlay)
             yield return audioLoader;
 
         source.clip = audioLoader.GetAudioClip(false);
         source.Play();
 
     }
 }

When I run the project, sound don't play and I get error without text: error

I have tried to delete all preferences and reinstall Unity, but it doesn't help. I'm really don't know what to do =(

error.png (180.5 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
1
Best Answer

Answer by gjf · Jan 26, 2016 at 11:17 PM

that's indicative of unity not finding your URL.

this code works for reading from a web server or local file system. it plays any sound currently set up (to ensure the audio source is working properly...)

 using UnityEngine;
 using System;
 using System.Collections;
 
 public class Loader : MonoBehaviour
 {
     private AudioSource _audioSource;
 
     private string _audioURL = "www.yourDomainHere.com/filename.wav";
     //private string _audioURL = "file:///Users/yourNameHere/Dropbox/filename.wav";
 
     //
     public void Start()
     {
         _audioSource = GetComponent<AudioSource>();
         if (_audioSource == null)
         {
             Debug.Log("No AudioSource component found!");
         }
         else
         {
             if (_audioSource.clip != null)
             {
                 _audioSource.Play();
             }
 
             StartCoroutine(LoadAudioClip(_audioURL));
         }
     }
 
     //
     private IEnumerator LoadAudioClip(string audioURL)
     {
         Debug.Log("Loading clip from WWW");
 
         var audioLoader = new WWW(audioURL);
         var clip = audioLoader.audioClip;
 
         yield return new WaitUntil(() => clip.loadState.Equals(AudioDataLoadState.Loaded));
 
         if (clip.loadState.Equals(AudioDataLoadState.Loaded))
         {
             _audioSource.clip = audioLoader.GetAudioClip(false, false);
 
             Debug.Log("Playing clip...");
             _audioSource.Play();
         }
     }
 }

Comment
Add comment · Show 1 · 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 Killercrush · Jan 27, 2016 at 06:32 PM 0
Share

Thank you for the answer! It looks like the problem was in my sample file itself, despite that it played when I set it directly in AudioSource (maybe Unity Editor converted it somehow, when I import the file in Assets).

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

45 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

Related Questions

How to handle UnityWebRequest Errors when throws Curl 28 Error 1 Answer

Save and Load Audio from web 0 Answers

Stream Audio from a URL? 3 Answers

WWW.GetAudioClip - unsupported file types? 0 Answers

Creating a Custom Music folder - Works inside the editor - Issues with build. 0 Answers


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