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 /
This question was closed Sep 03, 2016 at 01:03 PM by TabuuForteAkugun for the following reason:

Cancelled the game I was having problems with. And all other projects work.

avatar image
1
Question by TabuuForteAkugun · Aug 28, 2016 at 05:22 PM · c#audioaudioclipglitch

Take 2: Audio silent in Play Mode.

This is a recurrence of the same issue. With a new Unity project created with a unityPackage of assets from the one that originally had this problem.

I can play music and SFX just fine within the editor. But nothing plays in Play mode or Windows build.

I checked everything. AudioSource active? Check. Listener enabled? Check. Mute on playback? Not enabled. Script that handles playback active? Check. I even looked at the Profiler!

alt text

I just can't get any sound from my game. I'm stumped.

The kicker is, I have the same scripts I use for playback in another project. And it works in that one. Everything else works. Just not audio. It worked in this one too and then suddenly stopped.

Specs: Unity 5.4.0p3 64-bit Windows 8.1 Custom audio system script for enabling music loops

 using UnityEngine;
 using System.Collections;
 
 public sealed class System_InfiniteBackgroundMusic {
     public float MusicLoopPoint;
     public AudioClip audioClip;
     
     public float Time {
         get {
             long p = position;
 
             p /= entire.Length;
 
             return p * audioClip.length;
         }
         set {
             double m = value / audioClip.length;
 
             position = (long)(m * entire.Length);
         }
     }
     public float Duration {
         get {
             return audioClip.length;
         }
     }
     public long SampleTime {
         get {
             return position;
         }
         set {
             if (value >= entire.Length) {
                 Debug.LogError("Value is larger than audioClip.samples");
                 return;
             }
             if (value < 0) {
                 Debug.LogError("Value is lesser than 0");
                 return;
             }
             position = value;
         }
     }
     public int SampleDuration {
         get {
             return entire.Length;
         }
     }
 
     float[] entire;
     long position;
     int sampleLoopPoint;
     string audioName;
     int channels;
 
     int start;
     AudioSource audioSource;
 
     public void Play(AudioSource source) {
         double mul = MusicLoopPoint / audioClip.length;
         sampleLoopPoint = (int)(mul * audioClip.samples);
 
         channels = audioClip.channels;
         audioName = audioClip.name;
         entire = new float[audioClip.samples * channels];
 
         audioClip.GetData(entire, 0);
 
         audioClip = AudioClip.Create(audioName + "_Loop", audioClip.samples, channels, audioClip.frequency, true, OnAudioRead, OnAudioSetPos);
 
         audioSource = source;
 
         audioSource.loop = true;
         audioSource.clip = audioClip;
         start = 0;
         position = 0;
         audioSource.Play();
     }
     public void Stop() {
         audioSource.Stop();
         position = 0;
     }
     public void Replay() {
         audioSource.Stop();
         start = 0;
         position = 0;
         audioSource.Play();
     }
     public void ChangeTrack(AudioSource audioSource, AudioClip newTrack, float loop) {
         if (audioClip != null) {
             Stop();
             Object.Destroy(audioClip);
         }
         audioClip = newTrack;
         MusicLoopPoint = loop;
         Play(audioSource);
     }
 
     public void FadeOut()
     {
         // Fade out the track. Use in FixedUpdate() or Update().
         float r = 1.0f;
         while (r != 0){
             audioSource.volume -= 0.05f;
             r -= 0.05f;
         }
         // When volume is 0 (muted), stop track.
         if (audioSource.volume == 0)
         {
             Stop();
         }
     }
     public bool GetPlayStatus() 
     {
         // Get playback status,
         return audioSource.isPlaying;
     }
     public string GetTrackName()
     {
         if (GetPlayStatus())
         {
             // Use this to determine if a certain track is playing.
             return audioClip.name;
         }
         else
         {
             return "NONE";
         }
     }
 
     void OnAudioRead(float[] data) {
         if (start <= 16) {
             start++;
             position = 0;
             for (int i = 0; i < data.Length; i++)
                 data[i] = 0;
             return;
         }
         int count = 0;
         while (count < data.Length) {
             data[count] = entire[position];
 
             position++;
             count++;
 
             if (position >= entire.Length) {
                 position = sampleLoopPoint * channels;
             }
         }
     }
     void OnAudioSetPos(int newPos) {
 
     }
 }

I would really appreciate advice. Is ths a bug with Unity itself?

screenshot-646.png (25.6 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

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

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

Play sound only when button is pressed 1 Answer

Audio or Music continuing to play between scenes 1 Answer

How to stop and re-start audio? 1 Answer

Can Not Play Disabled Audio Source 1 Answer

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