directsound.vb.svn-base

来自「MirUnleashed vb.net Module modMain」· SVN-BASE 代码 · 共 74 行

SVN-BASE
74
字号
'### Visual Basic.NET and Direct X9 Legend of MiR Project ###'
'### Mir Unleashed Client DirectX Sound Module ###'
'### http://www.lomcn.co.uk ###' '### Credits to TrueADM and DeathWish ###'

'### Currently not in use ###'

Imports Microsoft.DirectX
Imports Microsoft.DirectX.DirectSound
Imports Microsoft.DirectX.AudioVideoPlayback

Module DirectSound

    Public LastIndex As Integer

    Public DS As Microsoft.DirectX.DirectSound.Device
    Public SoundBuffer(50) As Microsoft.DirectX.DirectSound.SecondaryBuffer


    Public Sub InitalizeSound(ByVal TargetForm As Form)

        If SoundOn = True Then
            DS = New Device
            DS.SetCooperativeLevel(TargetForm.Handle, CooperativeLevel.Priority)
        End If
    End Sub

    Public Sub PlaySound(ByVal Path As String, Optional ByVal Looped As Boolean = False)

        OpenSound(Path, Looped)

    End Sub

    Public Sub OpenSound(ByVal Path As String, ByVal Looped As Boolean)
        Dim I As Integer
        Dim S As Integer

        If SoundOn = False Then Exit Sub

Start:
        For I = 0 To 50
            If SoundBuffer(I) = Nothing Then
                'if theres an error thats because it loads mob in defaults
                If System.IO.File.Exists(My.Application.Info.DirectoryPath & "\Wav\" & Path & ".wav") = True Then
                    SoundBuffer(I) = New SecondaryBuffer(New IO.FileStream(My.Application.Info.DirectoryPath & "\Wav\" & Path & ".wav", IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read), DS)
                    If Looped = False Then
                        SoundBuffer(I).Play(0, BufferPlayFlags.Default)
                    Else
                        SoundBuffer(I).Play(0, BufferPlayFlags.Looping)
                    End If
                End If



                Exit Sub
            End If
        Next I


        For S = 0 To 50
            If Not SoundBuffer(S) = Nothing Then
                If SoundBuffer(S).Status.Playing = False Then
                    SoundBuffer(S) = Nothing
                End If
            End If
        Next S


        GoTo Start


    End Sub

End Module

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?