#!perl =pod =head1 NAME mp3player.plx =head1 DESCRIPTION Plays MP3 files. Requires QuickTime 4.0 (currently in beta) and MPEG::MP3Info module (on CPAN). This may be developed into a larger program by the author, or perhaps someone else will take it and run with it instead (someone more suited to doing GUI work :). So far there are no keyboard controls, and a playlist should be added, and all that good stuff. Maybe skins, different appearances. Who knows? If you are inclined to, go crazy, and provide us with the changes. Also, this might not perform as well as other MP3 players, but it seems to perform as well as the QuickTime Player that comes with QuickTime 4.0. So the hope is that when 4.0 is no longer beta, it will be perform better. =head1 AUTHOR AND COPYRIGHT Chris Nandor E<lt>pudge@pobox.comE<gt>, http://pudge.net/ Copyright (c) 1999 Chris Nandor. This program is free and open software. You may use, modify, distribute, and sell this program (and any modified variants) in any way you wish, provided you do not restrict others from doing the same. =head1 VERSION v0.10, Friday, April 23, 1999 =cut use strict; use Data::Dumper; use File::Basename; use Mac::Events; use Mac::Files; use Mac::Fonts; use Mac::Movies; use Mac::QuickDraw; use Mac::Windows; use MPEG::MP3Info; use Mac::StandardFile; my($win, $file, $movie, $x1, $y1, $x2, $y2, $z, $bounds, $curr, @str, $tottime); EnterMovies() or die $^E; make_window(); start_movie($file); WaitNextEvent while ($win->window && draw_window()); ExitMovies(); sub make_window { $x1 = $y1 = 100; $x2 = 300; $y2 = 100 + 15; $z = 108; $bounds = Rect->new($x1, $y1, $x1 + $x2, $y1 + $y2); $win = MacWindow->new($bounds, "MP3 Player", 1, noGrowDocProc, 1); $win->sethook( redraw => \&draw_window ); $win->sethook( drawgrowicon => sub {1} ); SetPort($win->window); END { $win->dispose if defined $win; } } sub start_movie { if (get_movie($file)) { do_movie_info($file); $win->new_movie($movie, Rect->new(0, 108, $x2, $y2)); } } sub get_movie { $file = shift || ask_for_movie(); return unless $file; my $resfile = OpenMovieFile($file) or die $^E; $movie = NewMovieFromFile($resfile, 0, newMovieActive) or die $^E; CloseMovieFile($resfile); END { DisposeMovie($movie); } 1; } sub draw_window { my($front, $back) = (GetForeColor(), GetBackColor()); my $x = 15; TextFont(geneva()); TextSize(9); TextFace(bold()); MoveTo(10, 15); DrawString($str[0]); TextSize(9); TextFace(normal()); for (1 .. $#str) { $x += 15; MoveTo(10, $x); DrawString($str[$_]); } my $ncurr = t_format(curr_time()); if (!$curr || !$ncurr || $curr ne $ncurr) { RGBForeColor($back); PaintRect(Rect->new(10, $x + 5, $x2, $x + 20)); RGBForeColor($front); } MoveTo(10, $x + 15); DrawString(sprintf "%s / %s", $ncurr, $tottime); $curr = $ncurr; # print MCGetControllerInfo($movie), "\n"; 1; } sub do_movie_info { my $lfile = shift; my($info, $tag) = ( get_mp3info($lfile), get_mp3tag($lfile) ); $tag->{TITLE} = $tag->{TITLE} ne '' ? $tag->{TITLE} : (fileparse($lfile, '\..{1,3}$'))[0]; SetWTitle($win->window, $tag->{TITLE}); push @str, $tag->{TITLE}; push @str, $tag->{ARTIST} if $tag->{ARTIST} ne ''; if ($tag->{ALBUM} ne '' && $tag->{YEAR} eq '') { push @str, $tag->{ALBUM}; } elsif ($tag->{ALBUM} eq '' && $tag->{YEAR} ne '') { push @str, $tag->{YEAR}; } elsif ($tag->{ALBUM} ne '' && $tag->{YEAR} ne '') { push @str, "$tag->{ALBUM}, $tag->{YEAR}"; } push @str, $tag->{COMMENT} if $tag->{COMMENT} ne ''; push @str, ($info->{STEREO} ? "Stereo" : "Mono") . " @ $info->{FREQUENCY} Hz / " . "$info->{BITRATE}-kbps layer $info->{LAYER}"; $tottime = t_format(@{$info}{qw(MM SS)}); 1; } sub t_format { my($mm, $ss) = @_; return sprintf "%2.2d:%2.2d", $mm, $ss; } sub curr_time { my($scale, $time) = ( GetMovieTimeScale($movie), GetMovieTime($movie) ); my($mm, $ss); $time /= $scale; (int($time / 60), ($time % 60)); } sub ask_for_movie { my $lfile = StandardGetFile(sub { local $_ = $_[0]->ioNamePtr; return !/\.mp[23]$/; }, 0); return unless $lfile->sfGood; $lfile->sfFile; } __END__ -- Chris Nandor mailto:pudge@pobox.com http://pudge.net/ %PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10 1FF77F13 8180B6B6']) ===== Want to unsubscribe from this list? ===== Send mail with body "unsubscribe" to macperl-request@macperl.org