Jump to content

Load wav file into memory and play it with Autoit


Recommended Posts

#Include <WinAPIEx.au3>

Global $sWave = @ScriptDir & '\MySound.wav'
Global $iByte

$iSize = FileGetSize($sWave)
$tWave = DllStructCreate('byte[' & $iSize & ']')
$pWave = DllStructGetPtr($tWave)
$hFile = _WinAPI_CreateFile($sWave, 2, 2)
_WinAPI_ReadFile($hFile, $pWave, $iSize, $iByte)
_WinAPI_CloseHandle($hFile)

_WinAPI_PlaySound($pWave, BitOR($SND_ASYNC, $SND_MEMORY, $SND_NOWAIT))

While 1
    Sleep(1000)
WEnd

Link to comment
Share on other sites

It seems to be that I mixed up the link in my previous post!

Look here: or here: http://pastebin.com/KCpSRWs2

It is more or less the code which Yashied has posted in #3.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Thx u both for ur quick answers.

I think i want to use the because i have to add 30 wav files and its for me more comfortable to put it in my script, like this

#AutoIt3Wrapper_Res_File_Add=C:\mysoundfile_1.wav, sound, mysoundfile_1
#AutoIt3Wrapper_Res_File_Add=C:\mysoundfile_2.wav, sound, mysoundfile_2
#AutoIt3Wrapper_Res_File_Add=C:\mysoundfile_3.wav, sound, mysoundfile_3 
;soon on soon to 30   

#include "resources.au3" 


If $Action1 = True Then 
_ResourcePlaySound("mysoundfile_1", $SND_ASYNC) 
;soon on soon to $Action 30

and i did compile the script, but it will not play the recource sound at the moment :mellow:

Edited by John81
Link to comment
Share on other sites

  • Moderators

John81,

Your code seems fine and I can play wav files as resources without problem using very similar commands. :mellow:

What does AutoIt3Wrapper tell you when you try and load the files as resources? Could you post the output that you get in the SciTE console when compiling?

Have you checked with ResHacker that the resources are indeed loaded? Do not forget that you need to prevent upx from compressing the file or ResHacker will not display them, so you need a #AutoIt3Wrapper_UseUpx=n line in there as well. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

Hi Melba23,

At First i put now this in the line

#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_File_Add=C:\mysoundfile_1.wav, sound, mysoundfile_1
#AutoIt3Wrapper_Res_File_Add=C:\mysoundfile_2.wav, sound, mysoundfile_2
#AutoIt3Wrapper_Res_File_Add=C:\mysoundfile_3.wav, sound, mysoundfile_3 
;soon on soon to 30   

#include "resources.au3" 

If $Action1 = True Then 
_ResourcePlaySound("mysoundfile_1", $SND_ASYNC) 
;soon on soon to $Action 30

but still not work :mellow:

And the Infos i get after compiling are this

>"C:\Programme\AutoIt3\SciTE\..\aut2exe\aut2exe.exe" /in "C:\myscript.au3"
                       Ultimate Packer for eXecutables
                          Copyright (C) 1996 - 2008
UPX 3.03w       Markus Oberhumer, Laszlo Molnar & John Reiser   Apr 27th 2008

        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------
    646144 ->    300544   46.51%    win32/pe     myscript.exe

Packed 1 file.
>Exit code: 0    Time: 2.933

And when i use Recource Hacker there are still something compressed ?

P.S. i decompressed with upx the file manualy,and then i started the exe but no sound and in the recource now i can´t find any wav file there.

Edited by John81
Link to comment
Share on other sites

You are missing SciTE4AutoIt3, it brings multiple tools giving bucket-loads of improvements of the AutoIt experience, for example the AutoIt3Wrapper that you are trying to use here even though you don't have it... Which is weird.

The Resources UDF page you linked to even mentions SciTE4AutoIt3 multiple times, can't see how you missed that :mellow:

Edited by AdmiralAlkex
Link to comment
Share on other sites

I thought i have the SciTE4AutoIt3 already, thx man now it does work :mellow:

P.S. What is the different between ...

_ResourcePlaySound("mysoundfile_1", $SND_ASYNC) <-- with it or without this ?

Edited by John81
Link to comment
Share on other sites

This link might help you: http://msdn.microsoft.com/en-us/library/dd743680%28VS.85%29.aspx

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • 3 months later...

#Include <WinAPIEx.au3>
#Include <APIConstants.au3>

Global $sWave = @ScriptDir & 'MySound.wav'
Global $iByte

$iSize = FileGetSize($sWave)
$tWave = DllStructCreate('byte[' & $iSize & ']')
$pWave = DllStructGetPtr($tWave)
$hFile = _WinAPI_CreateFile($sWave, 2, 2)
_WinAPI_ReadFile($hFile, $pWave, $iSize, $iByte)
_WinAPI_CloseHandle($hFile)

_WinAPI_PlaySound($pWave, BitOR($SND_ASYNC, $SND_MEMORY, $SND_NOWAIT))

While 1
    Sleep(1000)
WEnd

Thanks for this! There was a missing #include that's necessary to make this run, I've included it in the quoted code.

Mich.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...