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
1
Question by ashjack · Dec 06, 2015 at 12:35 PM · audiowwwaudiosourcenot workingplay

audio.play does not work

I have used WWW.GetAudioClip() to import a song at runtime into my game. The import works perfectly, but when I try and play my sound, it does not play.

 public AudioSource adio;
 
     public void Start()
     {
         WWW www = new WWW("file://C:/sound.ogg");
 
         AudioClip a = www.GetAudioClip(true, false, AudioType.OGGVORBIS);
         adio.clip = a;
 
         adio.Play();

         Debug.Log (adio.isPlaying);
     }

The debug says that the sound is in fact not playing, but in the AudioSource component, I can clearly see that there is a clip variable, and I can even manually listen to it if I click on it and listen through the editor, so it's not a problem with the import.

What could possibly be causing the audio to not play? I have also tried adding a delay and using PlayOneShot(). playOnAwake makes no difference regardless of it's setting either.

Comment
Add comment · Show 3
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 Ego65 · Apr 22, 2016 at 12:29 PM 0
Share

i have a similar prob as you but in my case PlayOneShot is the only way to get it playing but its terrible thats way. i've got this prob since i did upgrade to 5.3.2 never had this prob before. all sounds working well but this new one since 5.3 maybe its a bug ???

avatar image TBruce · Jul 17, 2016 at 06:04 PM 0
Share

Did you ever solve this issue?

avatar image ashjack TBruce · Jul 17, 2016 at 07:23 PM 0
Share

Sorry, but I never did figure out what the problem was or how to fix it.

1 Reply

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

Answer by TBruce · Jul 17, 2016 at 08:15 PM

The problem with trying to play an audio clip with www is that if you do not wait until the audio has not completely loaded before trying to play the clip it will not properly work. Try this class out

 using UnityEngine;
 using System;
 using System.IO;
 using System.Collections;
 
 public class PlayAudioFile : MonoBehaviour
 {
     public AudioSource adio;
     
     public string filePath = "file://C:/sound.ogg";
 
     private AudioClip audioClip;
 
     public void Start()
     {
         StartCoroutine(LoadAndPlaySound(filePath));
     }
 
     IEnumerator LoadAndPlaySound(string filePath)
     {
         WWW www = new WWW(filePath);
 
         while(!www.isDone)
             yield return null;
 
         if ((www.bytesDownloaded > 0) && (www.audioClip != null))
         {
             // audioClip = www.GetAudioClip(false);
             audioClip = www.GetAudioClip(true, false, AudioType.OGGVORBIS);
 
             while (!audioClip.isReadyToPlay)
                 yield return www;
             audioClip.name = Path.GetFileNameWithoutExtension(filePath);
 
             PlayAudioClip();
         }
 
         yield return null;
     }
     
     public void PlayAudioClip()
     {
         if ((audioClip != null) && (audioClip.isReadyToPlay))
         {
             adio.PlayOneShot(audioClip);
         }
     }
 }
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

37 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

Related Questions

Play audio once not working 0 Answers

Audio is cut in script 0 Answers

Need help: new sound isnt played correctly anymore 2 Answers

audio is not playing during IEnumerator 1 Answer

WWW Audio - 404 Not Found (WWW.error) 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