Jump to content
Sign in to follow this  
NELyon

Cannot _SoundOpen

Recommended Posts

NELyon

So I'm working on a colab project with multiple languages (which is the reason for my odd coding habits), and I'm trying to make a little CUI mp3 player. Now, it seems no matter what I do, it'll do all except play the file. All of the error checks seem to work fine, like a non-existant file, non-mp3, no file, etc, but when I pass an actual MP3 file to it, it just fails to open. I've used a blank script with just a SoundPlay("file.mp3") and it has played them fine, so that's not the problem.

Here's the code.

#Include <Sound.au3>
#AutoIt3Wrapper_Change2CUI=y
Global $fLog = FileOpen("soundplay.log", 1);
If (Not $cmdline[0]) Then
    If(EnvGet("SOUND_PLAYING") and EnvGet("SOUND_NAME")) Then
        For $i = 1 to 5 step +1
            if(ProcessClose("soundplayer.exe")) Then
                logWrite("Killed sound " & EnvGet("SOUND_NAME"));
                ExitLoop;
            Else
                logWrite("Attempted to kill sound " & EnvGet("SOUND_NAME") & ", but it failed.");
            EndIf
        Next
    EndIf
    logWrite("soundplayer.exe called without arguments.");
    Exit;
EndIf
If (Not StringInStr($cmdline[1], ".mp3")) Then
    logWrite("soundplayer.exe called for a non-mp3 sound file.");
    Exit;
EndIf
If (Not FileExists($cmdline[1])) Then
    logWrite("soundplayer.exe called for a non-existant file.");
    Exit;
EndIf

EnvSet("SOUND_PLAYING", 1);
EnvSet("SOUND_NAME", $cmdline[1]);
$sSound = _SoundOpen($cmdline[1]);
If ($sSound) Then
    logWrite("Began playing sound " & $cmdline[1]);
    _SoundPlay($sSound, 1);
Else
    logWrite("Could not open the sound " & $cmdline[1])
    Exit
EndIf

logWrite("Ended playing sound " & $cmdline[1]);
EnvSet("SOUND_NAME", 0);
EnvSet("SOUND_PLAYING", 0);
Func logWrite($msg)
    $tStamp = @Mon & "/" & @MDAY & "/" & @YEAR & " - " & @HOUR & ":" & @MIN & ":" & @SEC;
    FileWrite($fLog, $tStamp & " - " & $msg & @CRLF);
    Return 0;
EndFunc

Here's the log output with no parameters, a non-mp3 parameter, an MP3 (but non-existant) parameter, and finally two with actual MP3 files passed.

05/10/2010 - 16:17:59 - soundplayer.exe called without arguments.
05/10/2010 - 16:18:04 - soundplayer.exe called for a non-mp3 sound file.
05/10/2010 - 16:18:12 - soundplayer.exe called for a non-existant file.
05/10/2010 - 16:18:48 - Could not open the sound feelthenoize.mp3
05/10/2010 - 16:19:02 - Could not open the sound E:\Code\Final Project\feelthenoize.mp3

Can anyone lend a hand?

Share this post


Link to post
Share on other sites
Melba23

NELyon,

As the Help file tells you, _SoundOpen returns an array. So you need to test that the return is indeed an array: :)

EnvSet("SOUND_PLAYING", 1);
EnvSet("SOUND_NAME", $testcmdline[1]);
$sSound = _SoundOpen($testcmdline[1]);

If IsArray($sSound) Then ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    logWrite("Began playing sound " & $testcmdline[1]);
    _SoundPlay($sSound, 1);
Else
    logWrite("Could not open the sound " & $testcmdline[1])
    Exit
EndIf

Works fine for me like that. :idea:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
NELyon

NELyon,

As the Help file tells you, _SoundOpen returns an array. So you need to test that the return is indeed an array: :)

EnvSet("SOUND_PLAYING", 1);
EnvSet("SOUND_NAME", $testcmdline[1]);
$sSound = _SoundOpen($testcmdline[1]);

If IsArray($sSound) Then ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    logWrite("Began playing sound " & $testcmdline[1]);
    _SoundPlay($sSound, 1);
Else
    logWrite("Could not open the sound " & $testcmdline[1])
    Exit
EndIf

Works fine for me like that. :idea:

M23

I.. just... OH MY GOD I LOVE YOU.

I completely forgot how to do that, it's been so long since I've AutoIt'd. Thanks for the help.

Share this post


Link to post
Share on other sites
Melba23

NELyon,

I completely forgot how to do that, it's been so long since I've AutoIt'd

You also seem to have forgotten to use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. Then you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read. :)

By the way, just to make you feel better, _SoundOpen only returns an array since we updated the UDF last year, so your original code was probably correct for earlier versions. :idea:

M23

Edit: Added update info.

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  

×