Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Audio [Solved] Audio is not playing

Discussion in 'Audio & Video' started by Solbirth, Feb 9, 2020.

  1. Solbirth

    Solbirth

    Joined:
    Dec 13, 2019
    Posts:
    4
    Using Unity 2019.2.11f1 Personal.
    This is for an Android Build.

    I've been trying to figure it out all day long! Audio is the final step to finishing my project, so it's been VERY frustrating. None of the solutions I've researched have helped me.

    I'm using MP3 files downloaded from zapsplat.com, ranging from 1.5 to 2.5 minutes in length.
    They play just fine in Windows media players and such, and when double-clicked in the project window. However, they don't play in inspector preview or during runtime. Debug logs show the clips are being played, there's even a slight lag when changing scenes.

    I have created an AudioManager object with script, attached AudioSource, AudioClips, and AudioListener to it. Here is my code:



    public class AudioManager : MonoBehaviour
    {
    public static AudioManager obj;

    public AudioSource bgm;

    public AudioClip homeBGM; //clip dropped into inspector
    public AudioClip gameplayBGM; //clip dropped into inspector

    private void Awake()
    {
    obj = this;
    bgm = GetComponent<AudioSource>();
    }

    public void PlayMusic(AudioClip clip)
    {
    if (bgm.isPlaying)
    {
    bgm.Stop();
    }

    bgm.clip = clip;
    bgm.Play();
    Debug.Log( "isPlaying: " + bgm.clip.name );
    }
    }


    Then I call PlayMusic() from my GameManager:


    private void Start()
    {
    AudioManager.obj.PlayMusic( AudioManager.obj.homeBGM );
    }


    And again when I change scenes:


    case GameStates.LOAD_LEVEL:
    gameCount++;
    SceneManager.LoadScene( "Level" + gameLevel.ToString(), LoadSceneMode.Additive );
    AudioManager.obj.PlayMusic( AudioManager.obj.gameplayBGM );
    state = GameStates.START_LEVEL;
    break;


    AudioManager and GameManager are in the same persistent scene, and levels are simply added to it. I'd SINCERELY appreciate some help on this.
     
  2. Solbirth

    Solbirth

    Joined:
    Dec 13, 2019
    Posts:
    4
    ProgAudio.jpg My Project Settings.
    ImportAudio.jpg My Import Settings - both BGMs identical.
    InspAudio.jpg My AudioManager Inspector Settings.
     
  3. Solbirth

    Solbirth

    Joined:
    Dec 13, 2019
    Posts:
    4
    o_O... Okay, I feel like an idiot now. The sounds were actually starting/playing just fine by all indications. Though, I didn't hear anything when previewed/during run-time because my PC System volume was set to zero for my app/project.

    :cool: On the bright side, there's a slight chance this may be the case for others having mute audio problems.
    Windows10 Taskbar > Right-click Volume icon > Open Sound Settings > Advanced Volume Settings / App Volume.
     
    Last edited: Feb 9, 2020