XNA Creators Club Online
Page 1 of 1 (7 items)
Sort Posts: Previous Next

XACT2 Tool: Stopping A Cue

Last post 9/20/2009 9:56 PM by George Clingerman. 6 replies.
  • 9/19/2009 5:24 PM

    XACT2 Tool: Stopping A Cue

    I am having some problems when trying to stop a cue from playing in my game. The code I am using is posted below. The sound that I am trying to stop is set to loop as a background sound if this makes any difference. I am calling the stop sub but the sound carries on.

    P.s Forgot to mention I am using VB not C# so hopefully someone who knows VB can help.

    Public Sub StopSound()

            Try
                Cue.Stop(AudioStopOptions.Immediate) 'Stop Sound Immediatly'
            Catch ex As Exception
            End Try

    End Sub
    Speed - Now Available For Download
  • 9/20/2009 8:04 AM In reply to

    Re: XACT2 Tool: Stopping A Cue

    You're probably stopping the wrong cue? We're going to need to see more than your StopSound function. Why is that Try block there? You shouldn't need it.
    Kevin Gadd, Squared Interactive
    Development Blog | Twitter
    Help playtest my game, Inferus!
  • 9/20/2009 9:56 AM In reply to

    Re: XACT2 Tool: Stopping A Cue

    Ok not sure about the try block is there tbh I was using an XACT tutorial for this.

    Here is my audio module:

    #Region "Imports"

    Imports Microsoft.Xna.Framework
    Imports Microsoft.Xna.Framework.Audio

    #End Region

    Module Audio

    #Region "Objects/Variables"

        Public Cue As Cue
        Public SoundBank As SoundBank
        Public AudioEngine As AudioEngine
        Public WaveBank As WaveBank

    #End Region

        Public Sub PlaySound(ByVal CueName As String)

            If Game.SoundEnabled = True Then
                Try
                    Cue = SoundBank.GetCue(CueName) 'Get Sound File From Sound Bank'
                    Cue.Play() 'Play Sound File'
                Catch ex As Exception
                End Try
            End If

        End Sub

        Public Sub StopSound()

            Try
                Cue.Stop(AudioStopOptions.Immediate) 'Stop Sound Immediatly'
            Catch ex As Exception
            End Try

        End Sub

        Public Sub InitilizeSoundEngine()

            'Initialize Sound Objects'
            AudioEngine = New AudioEngine("..\..\Audio\Game Audio.xgs")
            WaveBank = New WaveBank(AudioEngine, "..\..\Audio\Wave Bank.xwb")
            SoundBank = New SoundBank(AudioEngine, "..\..\Audio\Sound Bank.xsb")

        End Sub

        Public Sub DisposeEngine()

            'Dispose Of Objects If Required'
            AudioEngine.Dispose()
            WaveBank.Dispose()
            SoundBank.Dispose()

        End Sub

        Public Sub UpdateEngine()

            'Update The Engine/Should Be Called As Often As Possible'
            AudioEngine.Update()

        End Sub

    End Module


    Here is how I am getting the sound to play:

    PlaySound("Back" & CurrentBackSound)


    And here is where I am trying to stop it:

    Game.PreviousBackSound = Game.CurrentBackSound
    Game.CurrentBackSound = GenBackSoundNo(Game.PreviousBackSound)
    StopSound()
    PlaySound("Back" & Game.CurrentBackSound)
    Speed - Now Available For Download
  • 9/20/2009 2:26 PM In reply to

    Re: XACT2 Tool: Stopping A Cue

    Are you calling the UpdateEngine method from within the Update Loop of your game? And definitely get rid of those Try..Catch blogs in that audio engine. All they are doing is masking errors you may be getting.
  • 9/20/2009 9:42 PM In reply to

    Re: XACT2 Tool: Stopping A Cue

    Ye I am calling it every update loop. Should I be doing this? I will take the Try..Catch Statements out.
    Speed - Now Available For Download
  • 9/20/2009 9:49 PM In reply to

    Re: XACT2 Tool: Stopping A Cue

    Just had a thought. Do you think that using a Module instead of a class may have something to do with it? This is the only thing I did different to the tutorial I used.
    Speed - Now Available For Download
  • 9/20/2009 9:56 PM In reply to

    Re: XACT2 Tool: Stopping A Cue

    I'm not sure. It's been a while since I've thought about VB. I think a module is a lot like making a Static class in C#. I'm not sure about the variables though. Maybe they are going out of scope? Try turning it into a class and seeing if that clears it up for you would be what I would suggest. Shouldn't take you too terribly long to test.
Page 1 of 1 (7 items) Previous Next