I'm working on an alternative client for iRATE (http://irate.sourceforge.net/) in Perl/Tk. For the purpose of this question, the important thing is I'm trying to play mp3s one at a time using Xmms::Remote.

To play a single mp3 with Xmms::Remote, I create a one-file playlist and call the play method. Then -- here's the tricky part -- I have to find out when the song is over so I can play the next one.

The only way to detect this is the is_playing() method, which will return true as long as xmms is still playing. I have to put the next song on as soon as it returns false.

In the meantime, while the mp3 is playing, I have to handle all the usual Perl/Tk events, button-clicks and whatnot. Naively polling for the end of the song would lock up the app.

I'm new to Perl/Tk and event-based programming, but it seems this event I'm waiting for (is_playing returning false) is a lot like the events Perl/Tk's MainLoop is waiting on already.

Forgive me if I'm stupid and I missed some obvious documentation somewhere, but can anyone tell me how I can set up my own non-gui-related Perl/Tk event to handle this?


In reply to setting up non-gui callbacks in Perl/Tk by forrest

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.