BUU has asked for the wisdom of the Perl Monks concerning the following question:

Basically my question is this. Does anyone know of a good mp3 player that i could interface with via a mp3 script? Basically i'm looking for some kind of library i could call from perl, like my $mp3=new Player; $mp3->load('song.mp3'); $mp3->play; I googled and searched cpan to no avail. The catch here, is that i need it to work on windows. I found two solutions that looked golden on cpan, however, the first one: MPEG::MP3Play requires a program that is no longer available, and the second Audio::Play::MPG123 appears to not work on windows. Any help?

Replies are listed 'Best First'.
Re: Perl Mp3 Player
by Albannach (Monsignor) on Sep 19, 2002 at 03:22 UTC
    Well I don't know your opinion of Winamp, but at least it has a defined API. You can even do very basic stuff via the command line.

    Update ...and strangely enough there is also Winamp::Control

    --
    I'd like to be able to assign to an luser

      Here's a (slightly trimmed) script I use to control Winamp:
      #!c:/perl/bin/perl -w use strict; use Win32::API; use constant WM_USER => 1024; use constant WM_COMMAND => 273; my %commands = ( PREV => 40044, NEXT => 40048, PLAY => 40045, PAUSE => 40046, STOP => 40047, # Lots of other commands trimmed for space... ); my $cmd = uc shift; if (exists $commands{$cmd}){ my $FindWindow = new Win32::API( 'user32', 'FindWindow', ['P', 'N'], 'I' ); my $SendMessage = new Win32::API( 'user32', 'SendMessage', ['I', 'I', 'I', 'I'], 'I' ); my $hwndWinamp = $FindWindow->Call('Winamp v1.x', 0); $SendMessage->Call( $hwndWinamp, WM_COMMAND, $commands{$cmd}, 0 ) if $hwndWinamp; } else { print "Invalid command.\n"; }
      The most useful Winamp related script I have is the one that locks my computer and pauses Winamp. This snippet checks to see if Winamp is currently playing, and if so sends a "pause" command:
      if ($hwndWinamp){ if ($SendMessage->Call($hwndWinamp,WM_USER,0,104) == 1) { $SendMessage->Call($hwndWinamp,WM_COMMAND,40046,0); } }

      --grummerX

      "It requires the httpQ winamp-plugin ". I can not find this on winamps offical site. Thats one thing, another thing is that requires winamp, which would take up a lot (relatively speaking) of extra resources for the gui and so forth. As opposed to just playing the bloody mp3.
Re: Perl Mp3 Player
by t0mas (Priest) on Sep 19, 2002 at 05:28 UTC
    Once upon a time, I did a learning project (for the Win32::GUI) module that I called MonkAmp. It was a win32 mp3 player that uses an XS interface to the amp11lib (GNU GPLd) that I wrote for this project.

    If you want to play with it yourself, I found amp11 and amp11lib at http://www.ph.tum.de/~nbeisert/amp11.html and http://marvin.cc.fer.hr/~elf/amp11lib/. Amp11lib have a very nice well-defined interface.

    If you want my code, please /msg me with your email address and I'll try to get the time to find the code, pack and send it to you.

    Good luck,

    /brother t0mas

    Update:

    You can use the built-in mci functions of Windows to do somthing like:
    #!/usr/bin/perl -w use strict; use Win32::API; use vars qw($mci $retstring $stop); #- Import mciSendStringA $mci = new Win32::API("winmm", "mciSendStringA", 'PPNN', 'N') or die "No we have no bananas...."; #- Init $retstring $retstring=" "x256; #- Open mp3 file $mci->Call("open whatever.mp3 alias mysound",$retstring,256,0); #- Play it $mci->Call("play mysound from 1",$retstring,256,0); #- Until... print "press Enter to stop playing...."; $stop=<STDIN>; #- Stop $mci->Call("stop mysound",$retstring,256,0); #- Close $mci->Call("close mysound",$retstring,256,0);
    Works like a charm om my Windows ;-) Let's call it BUUAmp...

      One can play mp3 files using Perl & SDL, too. cf. http://reneeb-perlblog.blogspot.com/2012/01/mp3s-mit-perl-abspielen.html
Re: Perl Mp3 Player
by moxliukas (Curate) on Sep 18, 2002 at 23:29 UTC

    I think Win32::OLE could probably help, though I have never used it. Most of Windows things have hooks that can be accessible via OLE (At least Windows Media Player had such ability last time I looked)

    Unfortunately I can provide no further details of how to actually do the intefacing because I have no experience with this particular module. Hopefully this could lead on to the right track

Re: Perl Mp3 Player
by BUU (Prior) on Sep 18, 2002 at 23:24 UTC
    Update:
    I found a windows version of mpg123 for windows, but i am unsure how i could best interface it with perl, as the mpg123 perl module itself returns "Your vendor has not defined Fcntl macro F_SETFL, used at MPG123.pm line 44" when i attempt to use it with the windows binary for of mpg123.

    Update, Part Two:
    The mpg123.exe i found for windows appears to have several major flaws, namely taking over my sound card and refusing to relinquish control, to the point of not allowing it to play multiple streams. Very bad, as i really liked the idea of mpg123 and it would be very nice if i could find a windows version.
Re: Perl Mp3 Player
by BUU (Prior) on Sep 19, 2002 at 03:46 UTC
    And while i'm messing about with perl/mp3 stuff, i tried the following and it repeatedly crashed perl/bash:
    perl -e'open I,"X.mp3"; binmode I; print <I>;
    However, just doing the open/binmode and leavint out the print ran fine. Am i running into something funky here? Will perl not read an mp3 file? (i was attempting read the mp3 so i could pipe it to a player reading from stdin)
    running 5.6.1, activestate version, and bash via the cygwin emulation dealy.
      It won't be perl/bash - the data in the mp3 will contain ansi escape characters or ^D (exit?), etc that will be harassing your poor terminal.

      Redirect output to a file, and cksum the original/new files, they should match.