in reply to Re^2: Playing wav files
in thread Playing wav files

I tried the Perl but found a problem which causes a message saying "perl.exe has stopped working".
I am using Perl version 5.028000
The area where it failed is
$WAV->Load($data); # get it $WAV->Write(); # hear it 1 until $WAV->Status(); # wait for completion
Specifically the line ...Load was ok
..but I did not get a print statement working after the row ...Write
I did try removing the '1 until' because it did not look like proper Perl
Any clues about how to make this work would be appreciated.

Replies are listed 'Best First'.
Re^4: Playing wav files
by poj (Abbot) on Feb 09, 2019 at 15:04 UTC

    This works for me on Windows 10 Perl v5.16.1 Win32::Sound 0.51

    #!perl use strict; use Win32::Sound; printf "%s %s\n",$^V,$Win32::Sound::VERSION; Win32::Sound::Volume('100%'); for my $n ('01'..'10'){ my $wav = 'C:/Windows/media/Alarm'.$n.'.wav'; print "Playing $wav\n"; Win32::Sound::Play($wav); }
    poj
      Thank you for that - it works on my system as well! I will have to look at the differences between your Perl and the one that failed for me.
        I now have found out why - it is all about \ and / in file names.
        Originally I had:
        C:\Windows\media\xxx.wav;
        which failed - to make it work I needed files names of the form
        C:/Windows/media/xxx.wav;
Re^4: Playing wav files
by pryrt (Abbot) on Feb 09, 2019 at 17:14 UTC

    1 until $WAV->Status(); is perfectly-valid perl; it's using the Statement Modifiers syntax rather than the Compound Statements syntax. I didn't come up with most of that example: except for the for loop at the end, it's verbatim from the Win32::Sound documentation, specifically their EXAMPLE at the end: everything until the ############ was theirs, not mine, and should work. That line, specifically, is saying "loop doing nothing (1 is a noop, in that case) until $WAV->Status() is true"; that status will go true when the wav is done playing.

    If it's not working, there's something wrong with your perl installation or Win32::Sound installation on your machine.

    Are using Strawberry Perl, ActiveState, cygwin, or WSL (Windows Subsystem for Linux)? The full output of perl -V (that's a capital V) might help us debug what's going wrong, along with perl -MWin32::Sound -le "print $INC{'Win32/Sound.pm'}; print $Win32::Sound::VERSION".

      Fair enough - it was something I simply had not seen before so I will look more carefully at your Perl and some references etc!