Audio-Play-MPG123

 view release on metacpan or  search on metacpan

mpg123/tools/Mp3play  view on Meta::CPAN

    if($#Track!=-1)
     {						# there are still tracks to play
      Display("list-full");
     }
    else
     {						# no tracks to play - quit
      $Exit=1;
     }
   }
  if(($_ eq "+")||($_ eq "kI"))
   {						# ASCII "+" or termcap's insert
						# character - add a single track
						# or tracks in a directory or
						# tracks in a playlist to play
						# list at current position
    $ReadingLinePrompt="Add to playlist: ";
    $ReadingLine=1;
    $AddingTrack=1;
    $ReadingLineStartPos=0;
    $ReadingLineCurrentPos=0;
    $ReadLine="";
    $ReadingLineExpandToFileName=1;
    $ErrorAddingToPlayList=0;
    Display("reading-line");
    ShowCursor();
    next;
   }
  if(unpack("C",$_)==23)
   {						# ASCII "Ctrl-W" - save play
						# list
    $ReadingLinePrompt="Save playlist to: ";
    $ReadingLine=1;
    $SavingPlayList=1;
    $ReadingLineStartPos=0;
    $ReadingLineCurrentPos=0;
    $ReadLine=$SavedPlayList;
    $ReadingLineExpandToFileName=1;
    Display("reading-line");
    ShowCursor();
    next;
   }
 }
continue
 {
  select(undef,undef,undef,0.05) if(($#UnreadMP3Info==-1)&&($KeyboardInput eq ""));
  						# sleep 50 miliseconds if there
  						# are no unread MP3 infos and no
  						# keyboard input is present
 }
ShowCursor();
ClearScreen();
MyExit(0);

sub ReadDirectory
{						# subroutine to read all MP3
						# files from a directory
 my $Entry;
 my @DirectoryContents;
 my $dev;
 my $inode;
 ($dev,$inode)=stat($_[0]);
 if((!$Directory{$dev,$inode})&&(opendir(DIRECTORY,$_[0])))
  {						# this directory has not been
  						# searched yet and could be open
  						# so read it
   $Directory{$dev,$inode}=1;			# this directory is searched
   $_[0].="/" if($_[0]=~/[^\/]$/);		# add "/" to the end of
   						# directory if it hasn't one
   @DirectoryContents=readdir(DIRECTORY);	# read directory contents
   closedir(DIRECTORY);
   foreach $Entry (@DirectoryContents)
    {						# check every entry in this
    						# directory
     if(-d $_[0].$Entry)
      {						# entry is a directory so go
      						# recursive into it if it isn't
      						# "." or ".."
       ReadDirectory($_[0].$Entry) if(!(($Entry=~/^\.$/)||($Entry=~/^\.\.$/)));
      }
     else
      {						# entry is a file
       if($Entry=~/\.[mM][pP]3$/)
        {					# file ends with ".mp3" (case
        					# insensitive)
         push @Track,$_[0].$Entry;
         $TrackCount{$_[0].$Entry}++;
         ReadMP3Info($_[0].$Entry) if(!$DontReadMP3InfoOnLoad);
        }
      }
    }
  }
}

sub ReadMP3Info
{						# subroutine to read MP3 info
						# from file
 $MP3InfoRead{$_[0]}=1;				# MP3 info is read
 if(open(MP3FILE,$_[0]))
  {						# MP3 file opened
   $MP3File=$_[0];
   binmode(MP3FILE);				# binary mode is required
   seek(MP3FILE,-128,2);			# seek to ID3 Tag
   read(MP3FILE,$_,3);				# read tag identifier
   tr/[a-z]/[A-Z]/;
   if($_ eq "TAG")
    {						# this MP3 file contains MP3
    						# ID3 Tag info, so read it
     read(MP3FILE,$_,30);
     s/[\000-\037\200-\377]//g;
     s/ *$//;
     $Title{$MP3File}=$_;
     read(MP3FILE,$_,30);
     s/[\000-\037\200-\377]//g;
     s/ *$//;
     $Artist{$MP3File}=$_;
     read(MP3FILE,$_,30);
     s/[\000-\037\200-\377]//g;
     s/ *$//;
     $Album{$MP3File}=$_;
     read(MP3FILE,$_,4);
     s/[\000-\037\200-\377]//g;



( run in 2.740 seconds using v1.01-cache-2.11-cpan-a49fcb8fa48 )