Making progress. I just ran the following on my computer: It played the wave once when it created it, once each for 'sinus.wav', './sinus.wav', and for the tempdir version, then finally played the WindowsDefault / error chime when it could not find 'DoesNotExist'. So, that means as long as the file exists and is readable (and is a valid wave file, presumably), Win32::Sound::Play() does what I expect.
Please add a fourth and a fifth entry to the for-loop: once for a local copy of your .wav, and once for the copy that's in some other directory. Then run the following script, and report the results.
use warnings;
use strict;
use Win32::Sound;
# Create the object
my $WAV = new Win32::Sound::WaveOut(44100, 8, 2);
my $data = "";
my $counter = 0;
my $increment = 440/44100;
# Generate 44100 samples ( = 1 second)
for my $i (1..44100) {
# Calculate the pitch
# (range 0..255 for 8 bits)
my $v = sin($counter*2*3.14) * 127 + 128;
# "pack" it twice for left and right
$data .= pack("CC", $v, $v);
$counter += $increment;
}
$WAV->Load($data); # get it
$WAV->Write(); # hear it
1 until $WAV->Status(); # wait for completion
$WAV->Save("sinus.wav"); # write to disk
my $otherFile = $ENV{TEMP} . '/sinus.wav';
$WAV->Save($otherFile); # write to disk elsewhere
$WAV->Unload(); # drop it
############
$|++;
for('sinus.wav', './sinus.wav', $otherFile, 'DoesNotExist') {
sleep(1);
printf "'%s' does%s exist and is%s readable\n", $_, (-f $_ ? '' :
+' not'), (-r $_ ? '' : ' not');
Win32::Sound::Play($_);
(my $f = $_) =~ s{/}{\\};
print qx(cmd.exe /c dir /N "$f");
print "\n" x 4;
}
__END__
'sinus.wav' does exist and is readable
Volume in drive C is Windows
Volume Serial Number is XXXX-XXXX
Directory of C:\usr\local\share\PassThru\perl\perlmonks
02/08/2019 03:08 PM 96,278 sinus.wav
1 File(s) 96,278 bytes
0 Dir(s) 113,186,381,824 bytes free
'./sinus.wav' does exist and is readable
Volume in drive C is Windows
Volume Serial Number is XXXX-XXXX
Directory of C:\usr\local\share\PassThru\perl\perlmonks
02/08/2019 03:08 PM 96,278 sinus.wav
1 File(s) 96,278 bytes
0 Dir(s) 113,186,381,824 bytes free
'C:\Users\pryrt\AppData\Local\Temp/sinus.wav' does exist and is readab
+le
Volume in drive C is Windows
Volume Serial Number is XXXX-XXXX
Directory of C:\Users\pryrt\AppData\Local\Temp
02/08/2019 03:08 PM 96,278 sinus.wav
1 File(s) 96,278 bytes
0 Dir(s) 113,186,381,824 bytes free
'DoesNotExist' does not exist and is not readable
File Not Found
Volume in drive C is Windows
Volume Serial Number is XXXX-XXXX
Directory of C:\usr\local\share\PassThru\perl\perlmonks
As you might be able to guess, since I am able to access a .wav in my local directory and in a different directory, I see no reason why it should not work for you; thus, I added the file-exists / file-readable test and dir output to give some clue as to what's going wrong for you.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.