Guest Posted March 11, 2014 Share Posted March 11, 2014 Hello, I am using the function _ResourcePlaySound (from Resources UDF) to play sound file from the exe. in my case i start to play some sound and my code(loop) must to keep running. so i can't use _ResourcePlaySound with the wait parameter to know when the sound stopped because the entire script will sleep. I need a way how to know if a sound still playing. I asked Zedna (The author of Resources UDF) and he said he don't know how to do it and it is related to PlaySound API. So how can i use PlaySound API to know if sound still playing? Thanks for helpers! Link to comment Share on other sites More sharing options...
JohnOne Posted March 11, 2014 Share Posted March 11, 2014 You know the length of the sound, you know when it's started. if start + time passed is less than start + length then sound is still playing. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 11, 2014 Moderators Share Posted March 11, 2014 gil900, in my case i start to play some sound and my code(loop) must to keep runningYou need to set the $Flag parameter of _ResourcePlaySound to $SND_ASYNC (0x1) to let the script continue. I see no way of detecting when the sound has stopped - so I suggest you do one of 2 things: - 1. Keep the sound looping until you want to end it by also setting the $Flag parameter of _ResourcePlaySound to $SND_LOOP (0x8). Now the sound file will repeat indefinitely until the script ends or you stop the resource from playing by using:DllCall("winmm.dll", "int", "PlaySound", "str", NULL, "hwnd", 0, "int", 0)- 2. Use some form of timer to tell you whether the resource has finished playing - you know the resource you are playing so you also know its length. I hope that helps. 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...
Guest Posted March 11, 2014 Share Posted March 11, 2014 You know the length of the sound, you know when it's started. if start + time passed is less than start + length then sound is still playing. I thought about this method.But what if the sound had not started at the right time (because the computer is screwed up or something like that)?You do not know what happened about that ..Also, I do not know what the length of the sound. I'll have to put that data to the array ..I prefer a more stable method. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 11, 2014 Moderators Share Posted March 11, 2014 gil900,Did you read my post above? 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...
Guest Posted March 11, 2014 Share Posted March 11, 2014 gil900, Did you read my post above? M23 I read it.in 2 you suggests the same method that JohnOne suggested. in 1 you suggests something that i don't want - that the sound will play from the beginning every time until the script is closed. I understand you wrong? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 11, 2014 Moderators Share Posted March 11, 2014 gil900,I understand you wrong?Yes, you can stop the playing sound at any time by running the code I posted. Try it and see. 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...
Guest Posted March 11, 2014 Share Posted March 11, 2014 (edited) gil900, Yes, you can stop the playing sound at any time by running the code I posted. Try it and see. M23 yes, you also worte: ..or you stop the resource from playing by using EDIT: But I do not see how it helps me.I need to know if the sound is playing or not .. the sound will stop anyway after it ends so i don't need to stop the sound.. i only need to know if the sound still playing or not. EDIT2: JohnOne, Suggested that: You know the length of the sound, you know when it's started. if start + time passed is less than start + length then sound is still playing. The problem is that it does not work properly if the sound had not started at the right time (because of slow computer)So my question is what are the chances of that happening - the case that the computer is slow and the sound starts after a delay of a few seconds.. If this case have very low probability then that method is fine Edited March 11, 2014 by Guest Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 11, 2014 Moderators Share Posted March 11, 2014 gil900,The earlier post you made in the Resources thread implied that you wanted to end the sound playing when your "other code" terminated, which is what I was trying to solve for you. However, if all you want is for the sound to play fully just the once then I see no alternative to the timer idea that both JohnOne and I suggested independently. 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...
Guest Posted March 11, 2014 Share Posted March 11, 2014 gil900, The earlier post you made in the Resources thread implied that you wanted to end the sound playing when your "other code" terminated, which is what I was trying to solve for you. However, if all you want is for the sound to play fully just the once then I see no alternative to the timer idea that both JohnOne and I suggested independently. M23 ok, Please reread the previous post after "EDIT2". I asked a new question there Link to comment Share on other sites More sharing options...
Zedna Posted March 11, 2014 Share Posted March 11, 2014 Just for the reference: My resources code is just wrapper over API function PlaySound described here at MSDN http://msdn.microsoft.com/en-us/library/windows/desktop/dd743680%28v=vs.85%29.aspx Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted March 11, 2014 Moderators Solution Share Posted March 11, 2014 gil900,I think I have found the answer. You need to attempt to replay the same sound using the $SND_NOSTOP parameter - this will not play if the current sound is still playing. This works for me: #AutoIt3Wrapper_Res_File_Add=sound.wav, sound, SoundTest #include <Resources.au3> ; Play the sound _ResourcePlaySound("SoundTest", $SND_ASYNC) ; Prove we have returned MsgBox(0, "Hi", "Sound should be playing") ; Now loop While 1 ; Try to replay the sound $vRet = _ResourcePlaySound("SoundTest", BitOr($SND_RESOURCE, $SND_ASYNC, $SND_NOSTOP)) ; If there is a return, the sound is no longer playing If $vRet Then ; Stop the sound from playing again DllCall("winmm.dll", "int", "PlaySound", "str", NULL, "hwnd", 0, "int", 0) ; Announce the end MsgBox(0, "Hi", "Stopped") ExitLoop EndIf WEndM23 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...
Guest Posted March 11, 2014 Share Posted March 11, 2014 gil900, I think I have found the answer. You need to attempt to replay the same sound using the $SND_NOSTOP parameter - this will not play if the current sound is still playing. This works for me: #AutoIt3Wrapper_Res_File_Add=sound.wav, sound, SoundTest #include <Resources.au3> ; Play the sound _ResourcePlaySound("SoundTest", $SND_ASYNC) ; Prove we have returned MsgBox(0, "Hi", "Sound should be playing") ; Now loop While 1 ; Try to replay the sound $vRet = _ResourcePlaySound("SoundTest", BitOr($SND_RESOURCE, $SND_ASYNC, $SND_NOSTOP)) ; If there is a return, the sound is no longer playing If $vRet Then ; Stop the sound from playing again DllCall("winmm.dll", "int", "PlaySound", "str", NULL, "hwnd", 0, "int", 0) ; Announce the end MsgBox(0, "Hi", "Stopped") ExitLoop EndIf WEnd M23 Thank you.I'll check it later.If I see that it works then I'll write a function for it which based on this method and I will share the function with you. Link to comment Share on other sites More sharing options...
Guest Posted March 14, 2014 Share Posted March 14, 2014 gil900, I think I have found the answer. You need to attempt to replay the same sound using the $SND_NOSTOP parameter - this will not play if the current sound is still playing. This works for me: #AutoIt3Wrapper_Res_File_Add=sound.wav, sound, SoundTest #include <Resources.au3> ; Play the sound _ResourcePlaySound("SoundTest", $SND_ASYNC) ; Prove we have returned MsgBox(0, "Hi", "Sound should be playing") ; Now loop While 1 ; Try to replay the sound $vRet = _ResourcePlaySound("SoundTest", BitOr($SND_RESOURCE, $SND_ASYNC, $SND_NOSTOP)) ; If there is a return, the sound is no longer playing If $vRet Then ; Stop the sound from playing again DllCall("winmm.dll", "int", "PlaySound", "str", NULL, "hwnd", 0, "int", 0) ; Announce the end MsgBox(0, "Hi", "Stopped") ExitLoop EndIf WEnd M23 Thank you!I checked it and it works!I created new wav named "Silent.wav" and with a length of 0.001 seconds and weighs 130 bytes. so that way i don't need to stop the sound ! I do not really like this way. But at the end what matters is that it works and I'd rather not to waste time for finding more normal way. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 14, 2014 Moderators Share Posted March 14, 2014 gil900,Great news! I created new wav named "Silent.wav" and with a length of 0.001 seconds and weighs 130 bytes. so that way i don't need to stop the sound !I did the same thing as I found you could get a short "blip" of the restarted wav before it was stopped. I was going to suggest it if you found the same problem. I do not really like this way. But at the end what matters is that it works and I'd rather not to waste time for finding more normal wayI do not think there is a "more normal" way. I searched for quite a long time to find this solution and I do not believe there is another one when you want to play the file in its entirety from the resource table. 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...
Guest Posted March 14, 2014 Share Posted March 14, 2014 (edited) I do not think there is a "more normal" way. I searched for quite a long time to find this solution and I do not believe there is another one when you want to play the file in its entirety from the resource table. Now I'm starting to remember that I thought in the past about "more normal" way. The method I thought about is to call _ResourcePlaySound with $Flag = 0 inside a separate "thread"(but the same exe and process). This way you can wait for the sound to stop playing without stopping script. if you can define variables in the separate "thread" and access them from the main thread then the idea is: In the separate "thread": $IsPlaying = True _ResourcePlaySound("Sound") $IsPlaying = False In the main "thread" While 1 If $IsPlaying = True Then ToolTip("Sound playing") Else ToolTip("Sound NOT playing") EndIf Sleep(10) WEnd I know that autoit not supports multithread. but i sow that people were able to do something very similar. So if this is true then it is probably enough to be used as "thread" I do not know how to implement this method. I'm not sure it's possible.I gave a new direction .. If you think it's possible so please try to exercise it or give me a start how to create that separate "thread" Edited March 14, 2014 by Guest Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 14, 2014 Moderators Share Posted March 14, 2014 gil900, I gave a new directionWhich I for one am not following. About time you did some research and coding, methinks. 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...
Guest Posted March 14, 2014 Share Posted March 14, 2014 (edited) gil900, Which I for one am not following. About time you did some research and coding, methinks. M23 If I understood what you said, you probably do not know how much research and coding i did.. I just saw that some people were able to create separate "thread". But I have not tried all solutions. EDIT According to the research I've done (which is not much .. I read people's comments), I realized that this direction is not worth it because it may cause the script to crash.But I also want to hear your research and what you say about it.EndEdit I need you to also answer the question:Is it possible to create a separate "thread" with the following requirements: * Ability to define and re-define the variables in the separate "thread"* Ability to access the variables in the separate "thread"* That separate "thread" will work on the same exe and processIf you know someone did it, so please give me a link to it. I also want to use it for InetRead (run InetRead in separate "thread") Thank you Edited March 14, 2014 by Guest 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