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

Hi perlmonks!
I wrote a little skript for listening music in my little black box.I copied the code of the Thread from cpan.

And now I have a problem.The skript is printing the length of the track an the position, thatīs fine, but then when the track should be finished, my skript doesnīt continue? o.O
Here comes the code:
print 'Total Length : '.$winmm- length(1),$/; while(1) { sleep 1; print 'Now Position: '.$winmm- pos(1)."\r"; } $winmm- close; print " \n\n\nTrack finished! \n\n\n";
It should close the song and print that the Track is finished. Can somebody find out whatīs wrong?


P.s: Sorry for my bad english ;)

Replies are listed 'Best First'.
Re: Win32::MediaPlayer what the...
by ikegami (Patriarch) on Jul 31, 2007 at 00:34 UTC

    A look at Win32::MediaPlayer's reveals it's a thin wrapper for mciSendString. mciSendString has limited capability for feedback. (It can be polled, but that's it.) It seems to work a lot like a remote control. A remote control doesn't know if a CD player is still playing the track the remote asked it to play or not. The CD player provides the feedback directly to the user.

    I suggest you copy the contents of Win32::MediaPlayer — It doesn't have a C component — and play around. The status command might be useful.

Re: Win32::MediaPlayer what the...
by menolly (Hermit) on Jul 31, 2007 at 17:37 UTC
    You've got a while(1) loop that will never end. Someting like while($winmm->pos(1) < $winmm->length(1)) will likely work better.