Strange but true,
I was working on exactly the same problem while reading this node ;).

Audio::Mpeg does however needs an external library, if I understand the docs correctly?
So I decided to try Corion's suggestion. And voila, flawless victory!

I'd kiss him if only he were a pretty girl. ;)

below my code, you might find it handy, allthough it could use some cleaning up. Messy teabag eh...

#!/usr/bin/perl -w #perltk wav/mp3 browser example use strict; use Tk; use Win32::Sound; use Tk::FileSelect; use Cwd; my $dir = "C:/Mijn\ documenten"; my $loop = 0; my @selected; my $Form1 = MainWindow->new; $Form1->title("Form1"); $Form1->geometry("400x200+8+8"); my $Label1 = $Form1->Label( -borderwidth => 1, -text => "initial dir:", -background => "#C0C0C0", -cursor => "", -font => "Tahoma 8 normal" ); $Label1->place( -width => 50, -height => 16, -x => 16, -y => 16 ); my $Edit1 = $Form1->Entry( -textvariable => \$dir, -cursor => "", -font => "Tahoma 8 normal" ); $Edit1->place( -width => 200, -height => 16, -x => 66, -y => 16 ); my $output = $Form1->Scrolled( "Text", -scrollbars => 'e' )->pack(); $output->place( -width => 390, -height => 100, -x => 15, -y => 90 ); my $Button1 = $Form1->Button( -text => "play", -cursor => "", -command => sub { &play(); }, -font => "Tahoma 8 normal" ); $Button1->place( -width => 75, -height => 25, -x => 5, -y => 40 ); my $Button2 = $Form1->Button( -text => "stop", -cursor => "", -command => sub { &stop(); }, -font => "Tahoma 8 normal" ); $Button2->place( -width => 75, -height => 25, -x => 105, -y => 40 ); my $Button3 = $Form1->Button( -text => "select mp3 file", -cursor => "", -command => sub { &openfd(); }, -font => "Tahoma 8 normal" ); $Button3->place( -width => 75, -height => 25, -x => 205, -y => 40 ); my $Button4 = $Form1->Button( -text => "select wav file", -cursor => "", -command => sub { &openfd2(); }, -font => "Tahoma 8 normal" ); $Button4->place( -width => 75, -height => 25, -x => 305, -y => 40 ); my $Check1 = $Form1->Checkbutton( -variable => \$loop, -text => "loop wav?" ); $Check1->place( -width => 100, -height => 17, -x => 20, -y => 70 ); my $fs = $Form1->FileSelect( title => "Load MP3 - File", -filter => "*.mp3", -directory => "$dir" #doesn't work yet! #-selectmode => 'multiple' ); my $fs2 = $Form1->FileSelect( title => "Load WAV - File", -filter => "*.wav|*.mp3", -directory => "$dir" #doesn't work yet! #-selectmode => 'multiple' ); tie( *STDERR, 'Tk::Text', $output ); tie( *STDOUT, 'Tk::Text', $output ); $SIG{'__WARN__'} = sub { print STDERR @_ }; MainLoop; ############################ SUBS ############################ sub play { foreach my $song (@selected) { if ( $song =~ m/mp3/gi ) { # plays one of Corions favourite songs! ;) print "playing mp3:\n$song\n"; system(qq{start "$song" "$song"}); } else { if ( $loop eq "1" ) { print "playing wav(looping):\n $song\n"; Win32::Sound::Play( "$song", SND_ASYNC | SND_LOOP ); } else { foreach $song (@selected) { print "playing wav:\n$song\n"; Win32::Sound::Play( "$song", SND_ASYNC ); } } } } } sub stop { Win32::Sound::Stop(); } #file dialog sub openfd { @selected = $fs->Show(); &printy(); } #file dialog2 sub openfd2 { @selected = $fs2->Show(); &printy(); } #prints the selection sub printy { foreach my $song (@selected) { print "selected:\n--------------------------------------\n$son +g\n" if defined $song; } }

Teabag
Sure there's more than one way, but one just needs one anyway - Teabag

In reply to Re: Playing MP3 file? by teabag
in thread Playing MP3 file? by Massyn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.