NELyon Posted May 10, 2010 Share Posted May 10, 2010 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. expandcollapse popup#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? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 10, 2010 Moderators Share Posted May 10, 2010 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 EndIfWorks fine for me like that. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
NELyon Posted May 10, 2010 Author Share Posted May 10, 2010 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. 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. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 11, 2010 Moderators Share Posted May 11, 2010 (edited) NELyon,I completely forgot how to do that, it's been so long since I've AutoIt'dYou 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. M23Edit: Added update info. Edited May 11, 2010 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now