No announcement yet.

How to FORCE CALLBACK action?

  • Filter
  • Time
  • Show
Clear All
new posts

  • How to FORCE CALLBACK action?

    I am about to write a program for a friend that plays an MP3
    or WAV file using mciSendString. I *want* to use a MODAL
    Dialog that will be used for my friend to select which song
    to play. Selecting the songs, and playing them, quitting the
    program, etc. aren't a problem. My problem is how to use
    the Dialog's Callback Function to process an action ON DEMAND.
    The on-demand action is the mci function that checks to see if
    the soundfile is finished being played. I can't simply put
    a loop in in the Callback Function to do this because then
    loop would preclude the ability (maybe?) to react to the user
    selecting a different song while a song is currently being
    played. Or does selecting a control in a Modal Dialog override
    any currently running code? Is it possible to use a thread
    from within the Callback to monitor the status of the song
    currently playing? But, maybe the thread would create contention
    with a new song being selected while one is currently playing?

    I need the on-demand processing so it CLOSEs the open mci-playing

    I know how to close it if a song is currently playing, and a new
    song is selected. That'd be easy to code in the %WM_COMMAND.

    What I need to be able to do is close the mci function if a song
    has finished playing and a new song has NOT been selected.

    In a nutshell, the program has to be able to monitor any
    currently playing files, and close the mci if it finishes.

    I already know how to do this using a MODELESS Dialog. For that,
    I could put the monitoring inside the WINMAIN's DOEVENTS loop.
    But, that seems kind of kludgey to me. Also, I'm interested in
    doing it with a MODAL Dialog so I can learn some new programming
    techniques, for future uses.

    Any ideas?

    Thanks in advance!

    Clay C. Clear

    [email protected]
    [email protected]

  • #2

    searching the forums for mp3 should give you most of what you are looking for. the following link in particular
    answers the questions you posed above...

    mailto:ti[email protected]
    Tsunami Record Manager


    • #3

      Sorry for misstating my question. I already know how to use
      mciSendString to play media. I've been doing it for quite a
      while, now.

      My question is: I *want* to use a Modal Dialog that the end user
      can use to select the songs to play. And, I already know how to
      make the program abort the song and start a new song if a song
      is currently playing and he selects a new one.

      What I need to know, when using a Modal Dialog, how to have the
      program monitor the song that is currently playing so it knows
      when it's done playing, so it knows to close the mci-playing
      function. This is ONLY necessary if the song is played to its
      end; as stated above, I know how to program it to end the song
      IF a new song is selected while the old song is still playing -
      that would be handled easily by the %WM_COMMAND.

      I already know how to program it do everything needed, IF I use
      a MODELESS Dialog. But, I want to get ideas for doing it with
      a MODAL Dialog, so I can learn something new that I can use
      in future (and this one) programs that have similar

      Any ideas?


      Clay C. Clear

      [email protected]
      [email protected]


      • #4
        The MCI API provides a way for notification messages to be sent to your specified callback... this should be details in - search for "MCI".

        Another method would be to create a thread that is launched when the play command is issued, and this thread could poll (monitor) the playback, and post a message back to your modal dialog.

        Personally, I'd opt for the MCI notification method.

        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        mailto:[email protected]


        • #5
          Thanks, Lance! But, before I go to the MS site, I'm going to
          check out my MultiMedia Help file, which I downloaded from the
          PB Download section quite a while back.

          Your reply brings up another question: I've never written a
          multithread program, before, so: can a Callback Function, or if
          needed, the WINMAIN Function, terminate a thread that is run
          from the Callback Function? It it can, then I will study that
          approach. I'll use the MCI approach, since you think it'd be
          better for this particular program, BUT, I want to learn
          about the thread approach for future programs' needs. Don't
          worry = I'm not asking you to post code, or go into a detailed
          summary; I can most likely figure it out myself from the
          win32.hlp, MSDN - January 2000 library, and the PB/DLL Help file.
          I just need to know if it CAN be done.

          Thanks, Lance!

          P.S. A personal question, if you don't mind - do you live
          outside of the USA? I've noticed that most of your replies
          to postings you post in the early (AM) hours. It's none of my
          business, so tell me to "go to heck", if you want. I'm just

          Clay C. Clear

          [email protected]
          [email protected]


          • #6

            Check the 14th message in the link I provided above... it will tell you about the following...
            To know when the MP3 playback is finished, you need to have an MM_MCINOTIFY handler in your callback function and include "notify" in your "play" command...
            mciSendString "play MP3 notify", "", 0, hDlg
            ' In your callback function...
            CASE %MM_MCINOTIFY
               ' The Windows Media Control Interface has just sent a notification
                  ' MP3 has finished playing successfully
                  mciSendString "close MP3", "", 0, hDlg
               END SELECT
            END SELECT
            mailto:[email protected]
            Tsunami Record Manager


            • #7
              It is no secret that I telecommute... I reside in New Zealand.

              Yes you can shut a thread down, but it is easiest to use a global variable which the thread can test occasionally to see if it should end itself.

              You'll find many examples of creating threads if you search the BBS.

              PowerBASIC Support
              mailto:[email protected][email protected]</A>
              mailto:[email protected]


              • #8
                Thanks, Lance! Funny thing is, I never thought of a GLOBAL
                variable that the thread could poll. I say it's "funny" because
                I already use GLOBAL variables, which we sort of discussed in
                another topic. OK, once I start working with multithreaded
                programs, I'll perview the postings in the Forums, if I can't
                figure it out myself (with help from the previously mentioned
                Help sources). Thanks, again!

                Thanks, Timm! After posting this reply, I'll print out a
                hardcopy of this topic for reference. Your posting saved me a
                LOT of research, most likely. Normally, I prefer to research
                stuff, myself, because in doing so I glean additional
                programming tidbits that I can use. But, since I use the MCI
                stuff extremely little, your source code will be a big help, so
                I don't have to use up too much time in researching stuff that
                I hardly ever use.

                Clay C. Clear


                [email protected]
                [email protected]


                • #9

                  Thanks for the tip about the FAQ Forum! I was just reading the
                  most recent Errata posting that you posted in it, and there's
                  a whole SLEW of information that I found useful! In fact, I'm
                  going to print out the whole topic later on today, when I have
                  the time for such a large printout.

                  Of particular use that I found was the errata (erratum?) about RESTting
                  UDT's. I use UDT's extensively in my coding, mainly in my own
                  private programs, but up until now, I've been brute force clearing
                  their members. I guess I've got a lot more reading and learning
                  to do.

                  Also, and I'm SURE that you already know this, but in case you
                  don't, I'll tell you so you can help other members with it, I've
                  found that, if a FUNCTION that is DECLAREd in an INC has an
                  argument that is "...AS ANY", and the programmer has to pass
                  "0" or a NULL argument to it, he MUST use BYVAL for that
                  argument when he calls the FUNCTION. At least, that's what I've
                  experienced. Sometimes, that may be contraindicated when the
                  FUNCTION usage requires a string for the argument; in those
                  cases, I've found using a NULL string literal ("") works.

                  I just realized that maybe using BYCOPY (by using parentheses)
                  might have the same effect?

                  There's no need to reply to this message, unless you need to
                  correct my observations.

                  Clay C. Clear


                  [email protected]
                  [email protected]


                  • #10
                    AS ANY tells PowerBASIC to pass a pointer. That is, AS ANY is a BYREF pass and the target data type is not type-checked. BYCOPY should work fine since a copy of the target is created, and it's address will be passed.

                    AS ANY places the onus on the programmer to pass the parameter (pointer) correctly.

                    PowerBASIC Support
                    mailto:[email protected][email protected]</A>
                    mailto:[email protected]


                    • #11
                      Thanks for clarifying that, Lance!

                      Clay C. Clear


                      [email protected]
                      [email protected]


                      • #12

                        Where did you find the Multimedia help file? I've been looking
                        for quite awhile & haven't found it.

                        Russ Srole

                        "There are two novels that can change a bookish fourteen-year old's life: The Lord of the Rings and Atlas Shrugged. One is a childish fantasy that often engenders a lifelong obsession with its unbelievable heroes, leading to an emotionally stunted, socially crippled adulthood, unable to deal with the real world. The other, of course, involves orcs." - John Rogers


                        • #13

                          I'm very sorry, but it's been so long since I acquired the file,
                          I have no clear recollection of where I got it from. I'm QUITE
                          sure that I downloaded it from PowerBASIC's Download section.
                          However, I just checked just about every folder in their Download
                          section, and I couldn't find it.

                          No, wait! I'm not sure if it's a "true" memory, but, I *think*
                          that I found the URL for the download site in a posting in one
                          of the Forums.

                          So, you can try a search for HLP or multimedia, with the search
                          spanning all of the Forums.

                          Or, as an alternative, since I was going to do it today anyway
                          (I promised my website visitors that I'd make my website complete
                          and fully operational today), I can right now upload the
                          MultiMedia Help file's archive to my website, along with the
                          HTML page containing the link to download it. I still have the
                          original archive in its entirety, backed up to Zip diskette.

                          It is now 12:07 Pm, Central Time Zone, USA. Go ahead and go to my
                          website at 12:30 PM, same time zone, and it'll be set up so you
                          can download it.

                          That's the best I can do for you. Sorry.

                          BTW, the URL listed in my signature is the one for my website.
                          That's the one you would need to go to to download the file.

                          Hope I've been of help!

                          Clay C. Clear


                          [email protected]
                          [email protected]