Win32::MediaPlayer - Module for playing sound MP3 / WMA / WAV / MIDI file on Win32 platforms
use Win32::MediaPlayer; $winmm = new Win32::MediaPlayer; # new an object $winmm->load('d:/10.mp3'); # Load music file disk, or an URL $winmm->play; # Play the music $winmm->volume(100); # Set volume after playing $winmm->seek('00:32'); # seek to #$winmm->pause; # Pause music playing #$winmm->resume; # Resume music playing print 'Total Length : '.$winmm->length(1),$/; # Show total time. while(1) { sleep 1; print 'Now Position: '.$winmm->pos(1)."\r"; # Show now time. };
This module allows playing of sound format like MP3 / WMA / WAV / MIDI on Win32 platforms using the MCI interface (which depends on winmm.dll).
Only working on Win32, and you should installed the Win32::API
if not you can install by ppm, in the console mode
type command:
ppm install http://www.bribes.org/perl/ppm/Win32-API.ppd
The new method is the constructor. It will build a connection to the mci interface.
$winmm = new Win32::MediaPlayer; # new an object
$winmm->load('d:/10.mp3'); # Load music from the disk, or Internet URL.
$winmm->play; # Play the music file.
The value should be a format like XX:XX, or you can fill the micro second integer of the music.
$winmm->seek(100000); # Seek the music file, at the 100 sec pos.
$winmm->seek('01:40'); # Seek the music file, at the 01 min 40 sec pos.
$winmm->close; # Close the music file.
The value is from 0 to 100
$winmm->volume(100); # Set volume to 100 after playing
Return the music total length
$length = $winmm->length(1); # Return the length in XX:XX format.
$length = $winmm->length; # Return the length in micro second integer.
Return the music now position
$length = $winmm->pos(1); # Return the Position in XX:XX format.
$length = $winmm->pos; # Return the Position in micro second integer.
Pause the music play
$length = $winmm->pause; # Pause the music play.
Resume the music play
$length = $winmm->resume; # Resume the music play.
Lilo Huang
Copyright 2006 by Lilo Huang All Rights Reserved.
You can use this module under the same terms as Perl itself.
To install Win32::MediaPlayer, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Win32::MediaPlayer
CPAN shell
perl -MCPAN -e shell install Win32::MediaPlayer
For more information on module installation, please visit the detailed CPAN module installation guide.