5 Replies Latest reply on Feb 7, 2014 7:53 PM by FentonJones

    Play Button Script

    AlexKalmakrian

      Title

      Play Button Script

      Post

           Hi.

           So I'm now trying to build a Music Library, which in itself is useful to be able to find records by genre, artist / composer etc.

           What I'd really love to do though, would be to be able to create a basic player inside of Filemaker Pro.

           I've created a 'Play' button, and a 'Stop' button, but they obviously do nothing at the moment without the appropriate script. I recognise that this is a complex thing for a novice FileMaker user like me to accomplish...

      The furthest I've got is:

           - Creating a new field called 'File'

           - Changed 'File' into a Container field

           - Inserted .mp3 file as QuickTime

           The result is that I don't like the way Filemaker appends the player within the cell (see attached screenshot.)

           Any further guide would be really appreciated. Thanks.

            

      Music_Library.png

        • 1. Re: Play Button Script
          davidanders

               If the sound file is inside a container field, then all you need to do is to use the "Go To Field" script step (under the navigation section) with the option "Select/Perform" checked. Please do not forget to choose the target field and also check the appropriate box. This is by far the simplest and cheapest way to accomplish what you need.

               However, if you need to play a sound file that resides OUTSIDE your database, then I believe you'll have to use an external plugin. 24U is a company that develops some good and useful plugins for FileMaker on both platforms -- Mac and Windows. They have a one for this task -- SimpleSound -- which is rather inexpensive.

          • 2. Re: Play Button Script
            IT_User

                 If you want something more visually appealing, possibly get out of Table View and use a List View.

                 Also, then it is easier to assign scripts to different things at that point.  It then gets to the complicated point that DavidAnders is talking about.

            • 3. Re: Play Button Script
              AlexKalmakrian

                   Hi DavidAnders and IT_User. Thanks very much for your help.

                   I'd already created a button in Browse view, and have now added the "Go To Field" script step with appropriate selection.

                   The file plays successfully, but now I can't get it to pause, resume play etc. I just lose all control of FileMaker until the song finishes. I have also created a 'Stop' button. In an ideal world I would use this button to perform a script that, you guessed it, stops the playing song.

                   Incredibly sorry for being so obtuse. Logic isn't my strong point...

                   Thanks again.

              • 4. Re: Play Button Script
                FentonJones

                      

                     This has been a few days ago, and I'm not sure this is useful nor desired. But I have spent some time trying to solve this kind of problem, years ago and recently. Basically, there is no "real easy" method which gives you a "perfect player" run by a FileMaker database. I have been able to create something which I like. It is for an Apple computer, as it runs via a tool already built in to the OS. It is a basic Unix command. FM can run it via its Perform AppleScript (which can run Unix commands with: do shell script "the command"). It is not complex however.

                     FM Script running Perform AppleScript:

                     set unix_raw_file to cell "File_Path" of current record

                     set unix_file to quoted form of POSIX path of unix_raw_file

                     try

                     do shell script "afplay -q 1 " & unix_file & " &> /dev/null &"

                     end try

                      

                     (* -q 1 tells it to use full volume; you can remove it, i.e., just "afplay ", or can make it less, i.e., " -q .9 " *)

                      

                      

                     The only thing you need to give it is the FM field "File_Path". That needs to be a Unix style path. This can be gotten different ways. It is what apps like iTunes uses. Example:

                     /Users/your_user_name/Music/Music_MP3/01 Fields of Gold.mp3

                     This can be gotten via a FM calculation from what FM uses, or from a Mac path (old still, with ":" instead of "/"). 

                      

                     There is one other command I use, which is used to stop playing the music, using another FM script, running via Perform AppleScript:

                      

                     try

                     do shell script "killall afplay"

                     end try

                      

                     It stops afplay, and the music stops. I also run that script before running the one above to "play" the music. Because a Mac can and will run 2 (or more) at the same time if you don't stop one that's already running. Not necessary if the first one is done, but doesn't hurt to run.

                      

                     "afplay" will run immediately, and well stop immediately also. It's a simple Unix command. It has few features. There is no "pause", for example.

                      

                     If you really need a "pause" and "resume" then you would need to tell the application "QuickTime Player", which can do that. You can run it somewhat similarly, using FM scripts running Perform AppleScript. But I prefer the simplicity of the Unix command.

                      

                      

                     I also have a short FM script to "show" me the music file itself, highlighted in its folder, also using Perform AppleScript:

                      

                     set unix_file to cell "File_Path" of current record

                     set mac_file to POSIX file unix_file

                      

                     tell application "Finder"

                     reveal file mac_file

                     activate

                     end tell

                      

                      

                     P.S. I have a file which does the above. But really, the method can be added to any FM file, which has the paths to the music file, with the above few scripts.

                     I also have a file which does similar using QuickTime Player. I could upload these files for people to download. But I would only want people who are willing to learn at least the basics for how to use them. I just built them for myself (years ago), so I could hear some music files, without the whole iTunes routine. I've always been messing with simple Apple tools. I am not however a professional anything now, do to a stroke 3 years ago (which makes it hard for me to read sentences {including some people's typing (not you :-}, etc.), and age (63).

                      

                     My file using "afplay" view:

                • 5. Re: Play Button Script
                  FentonJones

                        

                       This is more like what the "play with QuickTime" FM file looks like. Notice there's other windows involved. Though, I image those could be made less obvious; but that would require some more AppleScript lines. Or, the QT window(s) could be made to end up where you want them to (I moved this in place); but that would take quite a bit of "telling it exactly where you want it, depending on where exactly the FM file's window is"; all of wish is doable, with lots of "how much exactly" calcs, via FM and AS. Hence not done (yet). (Notice it does have FM buttons for "pause" and "resume", both in FM and QT).

                       This file is currently just to put a file into a Container field, as QuickTime. It would not, as is, handle plain file paths into a text field (like the other does, as Unix paths). However, that Container is really only so you can click into it; which you've already said you don't much like. Hence that could be removed, and a text file path be used. 

                       P.S. Both of these files are expectly a "local" file. Neither is really setup to run on FM Server, etc.. I imagine that can be done also, but I can't remember exactly  how. As I said, I'm not really up on all details (of even my own past).