Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-20 01:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found