Sign in to follow this  
Followers 0
nickston

flush sound buffer

13 posts in this topic

I have some audio player.

I suspend thread of this player in my script, but bit of full sound continue playing by loop.

How I can flush sound buffer or stop playing sound in that case?

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

It sounds like it's something only the player can.

Could you name the player and post (a bit of) your script?

The name of the player can be anyone, it's does not matter.

Func _SuspendExe($PID)  
    
Local $THREAD_SUSPEND_RESUME =0x0002
$oWmiService = ObjGet("winmgmts:\\.\root\CIMV2")
    $ThreadHandle = $oWmiService.Execquery("SELECT Handle FROM Win32_Thread WHERE ProcessHandle='" & $PID & "'")
    if isobj($threadHandle) then
        For $TID in $threadHandle
  ;Getting the handle of thread
        $hwnd = DllCall($hkernel32Dll,'hwnd',"OpenThread","int",$THREAD_SUSPEND_RESUME,"int",0,'int',$TID.handle)
        $ret = DllCall($hkernel32Dll,'uint',"SuspendThread",'hwnd',$hwnd[0])
        next
    EndIf
    
EndFunc

this is function which suspend thread. It's work good, but sound in buffer...

Edited by nickston

Share this post


Link to post
Share on other sites

What happens if you call this function just before you call the one you posted?

; Reduce memory usage
; Author wOuter ( mostly )


; Usage - 
;$pid = WinGetProcess("window title", "")
_ReduceMemory($pid)


Func _ReduceMemory($i_PID = -1)
    Local $ai_Handle, $ai_Return, $memory_counter
    $memory_counter = 1
    If $i_PID <> - 1 Then
        Sleep(150)
        $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
        Sleep(150)
        $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
        Sleep(150)
        DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
        Sleep(150)
    Else
        Sleep(150)
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
        Sleep(150)
    EndIf
    Return $ai_Return[0]
EndFunc  ;==>_ReduceMemory

Das Häschen benutzt Radar

Share this post


Link to post
Share on other sites

What happens if you call this function just before you call the one you posted?

; Reduce memory usage
; Author wOuter ( mostly )


; Usage - 
;$pid = WinGetProcess("window title", "")
_ReduceMemory($pid)


Func _ReduceMemory($i_PID = -1)
    Local $ai_Handle, $ai_Return, $memory_counter
    $memory_counter = 1
    If $i_PID <> - 1 Then
        Sleep(150)
        $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
        Sleep(150)
        $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
        Sleep(150)
        DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
        Sleep(150)
    Else
        Sleep(150)
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
        Sleep(150)
    EndIf
    Return $ai_Return[0]
EndFunc ;==>_ReduceMemory
Nothing.

Share this post


Link to post
Share on other sites

Who can help me?

Share this post


Link to post
Share on other sites

Ever thought about pausing or simply closing the media player??

And what about thought pausing?

Simply closing is bad idea ie player will continue play after stop

Share this post


Link to post
Share on other sites

And what about thought pausing?

Simply closing is bad idea ie player will continue play after stop

I am not sure what you mean, if you exit it there shouldn't be any sound??

ProcessClose("wmplayer.exe")

Share this post


Link to post
Share on other sites

I am not sure what you mean, if you exit it there shouldn't be any sound??

ProcessClose("wmplayer.exe")
I mean what player must be stopped but not closed. Player will continue play sound after some time and start playing at the position in which was stopped.

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I mean what player must be stopped but not closed. Player will continue play sound after some time and start playing at the position in which was stopped.

mr. nickston - I do not see how you will get any help on this issue if you cannot provide the name of the media player that is running whilst you are experiencing this phenomenon. As a last resort, open up the Task Manager - by pressing Ctrl-Alt-Del - and look for the name of processes that might be media players.

It is simple enough to automate the stopping or pausing of the wmplayer.exe if that is the name of the media player, we could even stop or pause other media players. If there is no real media player running, then other approaches could be reviewed if we had sufficient information on your script. Post some code as a last resort.

I have some audio player.

I suspend thread of this player in my script, but bit of full sound continue playing by loop.

How I can flush sound buffer or stop playing sound in that case?

Obvious to many programmers now - judging by your report here - suspending "a" thread of a media player is not a good idea.

There are switches for media player instantiation and there are COM object methods, etcetera.

Edited by Squirrely1

Das Häschen benutzt Radar

Share this post


Link to post
Share on other sites

mr. nickston - I do not see how you will get any help on this issue if you cannot provide the name of the media player that is running whilst you are experiencing this phenomenon. As a last resort, open up the Task Manager - by pressing Ctrl-Alt-Del - and look for the name of processes that might be media players.

It is simple enough to automate the stopping or pausing of the wmplayer.exe if that is the name of the media player, we could even stop or pause other media players. If there is no real media player running, then other approaches could be reviewed if we had sufficient information on your script. Post some code as a last resort.

Obvious to many programmers now - judging by your report here - suspending "a" thread of a media player is not a good idea.

There are switches for media player instantiation and there are COM object methods, etcetera.

Ok. I attempt to give more info about the situation in which I need stop proccess.

1) The "name of media player" (or other programms) obtain from out of my app (for example, from file). According to that names the App must stoping proccesses, ie I don't known that names.

2) I test my app on Winamp, and discover problem with sound.

3) According to 1) and 2) the name dosn't have matter, proccess must be stoped (don't depend of name), and sound must be stoped. But question is how stop sound.

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