Sign in to follow this  
Followers 0
IErrors

MCI _SoundPlay() Overload?

1 post in this topic

Hi everyone. I am rather new to AutoIt AND MCI so please forgive me if I am just doing something completely stupid here.

I am having an issue with the script below. It is used to set hotkeys for a-z and play a random wav file at key press. It seems to work fine for about 7 moderately spaced out keystrokes then just absolutely refuses to play anymore. _SoundPlay() returns 1 "Play Failed" and sometimes _SoundStatus() Returns 0 when the playing stops.

Any idea what is going on here? Am I just completely overloading MCI? Is that even possible?

Any help would be great!

#include <Array.au3> 
#Include <File.au3>
#include <Sound.au3>


AutoItSetOption("SendKeyDelay", 0)
Reg_MCI_Files()

$Num = 0
$i = 97
Dim $Letters[26]        ;~ 97 - 122 a-z

Do
    $Letters[$Num] = Chr($i)
    $num = $num + 1
    $i = $i + 1
Until $i = 123

For $i in $Letters
    HotKeySet($i, "Play")
Next

While 1
    Sleep(100)
WEnd

Func Play()
    Hotkeyset(@HotKeyPressed)
    Send(@HotKeyPressed)
    Hotkeyset(@HotKeyPressed, "Play")
    Do
        $R = Random(1, $Files[0], 1)
        ConsoleWrite(_SoundStatus($Audio[$R]) & @CRLF)
    Until _SoundStatus($Audio[$R]) = "stopped"
        ConsoleWrite(_SoundPlay($Audio[$R]) & "    " & @error & @CRLF)
EndFunc

Func Reg_MCI_Files()

    Global $Files = _FileListToArray(@ScriptDir, "*.wav", 1)
    _ArrayDisplay($Files)
    Global $Audio[$Files[0] + 1]
    $i = 0
    For $File in $Files
        $Audio[$i] = _SoundOpen($File)
        $i = $i + 1
    Next
    $i = ""
EndFunc

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0