Greetings fellow PerlMonks,
I'm trying to play an MP3 file in a game I'm writing with my son. The code is fairly simple:
use Win32::MediaPlayer;
use Cwd;
print "Current directory is ". getcwd . "\n";
$winmm = new Win32::MediaPlayer;
$winmm->load('c:/dev/roar.mp3');
print "Here.\n";
$length = $winmm->length;
print "length is $length\n";
$winmm->volume(100);
$winmm->play;
print "Done.\n";
The resulting output when run from a command prompt is:
C:\dev>perl game.pl
Current directory is C:/dev
Here.
No File Loaded at C:/Perl/site/lib/Win32/MediaPlayer.pm line 58.
length is 1453
No File Loaded at C:/Perl/site/lib/Win32/MediaPlayer.pm line 44.
Done.
When I run this, I hear no sound. I can play the roar.mp3 file in winamp with no problem. The roar.mp3 file is in the same directory as the game.pl file. The odd part is, the length echo is correct. The mp3 file is 1.453 seconds long. So how could the program know the length of the mp3 file if it supposedly did not load correctly?
I'm running this on Windows XP. I just installed the MediaPlayer module today. Any ideas why it's not playing? Can anyone offer an alternative suggestion for playing an mp3? (Since it's for a game, I want it to play embedded, without a player popping up.)
Thanks,
TROGDOR
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.