New in 14: AV playback interaction

Version 3

     

     

     

     

    In FileMaker Go 14, the user can view video and play audio directly from the layout rather than going full-screen, and can continue to interact with the solution while this media plays. This new opportunity for interaction is greatly enriched though the new scripting options listed below. By combining these elements, you can come up with sophisticated solutions for digital asset review, training authentication, and other interesting use cases:

    Script steps

    • AV Player Play starts the media playing.
    • AVPlayer Set Options changes the playback settings for media that is already playing.
    • AVPlayer Set Playback State changes the playback state of the currently playing media file.


    Script triggers

    • OnObjectAVPlayerChange causes a script to run when the playback state of the media within an object (i.e. container field or web viewer) changes.
    • OnFileAVPlayerChange causes a script to run if a media file is already playing and the playback state is changed.
    • OnExternalCommandReceived causes a script to run when the user affects playback of a media file from outside of FileMaker Go.


    Function

    • GetAVPlayerAttribute returns a range of attributes for the audio, video, or image file in a container field.




     


    Goal:


    Use the new AV script steps, trigger, and function to create a simple interactive process involving media playback.


    You’ll implement a simple series of triggered scripts that pause playback when a user makes a comment which watching a video. When the comment is saved, the paused position will be recorded with it, and the video will resume, playing automatically from that position.

     

    Because the paused position is recorded, the user doesn’t need to include that information in their comment, and anyone else viewing the comment can view that moment in the video to get a clear understanding of what the comment is about.

     

     

    Before you start:

     

    Make sure you have the Approvals example solution open in FileMaker Pro 14 on your desktop or laptop. This machine should be on the same local network as your iPad so that it’s available on the iPad as a hosted file.

     


    Steps:

     

    • Create the script to pause playback

      This script will pause playback of a media file (if any is playing), record the current playback position into a global variable, and then stop playback. If no media file is playing, the global variable is set to 0.

      This time it's up to you whether to enter the script using point-and-click or the new keyboard functionality. The steps are less specific to allow for this.

     

    1. Open the Script Workspace and create a new script called “Trigger | Pause playback”.

    2. Add an AVPlayer Set Playback State script step, changing the script option to “Paused”. This step will pause the playback of a currently playing media file.

    3. Add a Set Variable script step and name the variable: $$POSITION

    4. Type the following for the Value: If ( GetAVPlayerAttribute ( "playbackState" ) = 0 ; "" ; GetAVPlayerAttribute ( "position" ) )

      This expression returns the value 0 if playback has been stopped. Otherwise it returns the current (paused) playback position.

    5. Add another AVPlayer Set Playback State script step, changing the script option to “Stopped”. This step will change the playback state from paused to stopped.

    6. Compare your script to "Trigger | Pause playback FINISHED" to make sure it turned out properly.

    7. Save and close the script.


      Set up the OnObjectEnter script trigger

     

    1. Make sure you are viewing the “Approval Details | Go - MEDIA” layout (in the Go folder) in Layout mode.

    2. Control-click (OS X) or right-click (Windows) the Resources::zgt_Comment field in the middle of the screen.

    3. Select “Set Script Triggers…” from the resulting dropdown menu. A Set Script Triggers dialog window appears.

    4. Double-click the OnObjectEnter trigger in the list of triggers. A Specify Script dialog window appears.

    5. Double-click your new “Trigger | Pause playback” script. The script is selected and the Specify Script window closes.

    6. Click OK to save your changes and close the Set Script Triggers window.


      Create the script to resume playback

    7. Return to the Script Workspace and create a new script called “Resume playback”.

    8. Add an If statement with the condition: $$POSITION > 0

      If you have a positive value for $$POSITION, that means that you paused the playback of a media file and recorded this value.

    9. Within the If statement, add an AVPlayer Set Playback State script step, changing the script option to “Stopped”. This step will pause the playback of a currently playing media file, if one is running.


    1. Also within the If statement, add an AVPlayer Play script step. Now you'll change options for this step.

    2. Change the Source option to “Field”, choosing the “Image | Container” field (in Approvals).

    3. Set the Position option to the following: GetAsNumber ($$POSITION)

      This sets the starting position of the video to the value stored in $$POSITION. The GetAsNumber() function is needed because you must specify the position as the numeric equivalent of a time.

      That’s it — your script is done. But you still need to add it to a larger script that saves the user’s comment. This script is called when the Save button is tapped.


    1. Open the “Save Comment | Go” script.

    2. Add a Perform Script script step at the bottom of the script (after the comment “Add Resume Playback script here”).

    3. Select your new “Resume Playback” script as the script to be performed.


      Test the process on iPad


    4. Open the hosted Approvals solution on your iPad.

    5. Make sure you are viewing the Approvals List layout for iPad.

    6. Navigate to the “Running in the grass” Approval record.

    7. Tap on the video file icon that appears above the file name, then choose the "Play" option.

    8. Tap the Approve button while the video is playing. Observe that the button script runs, demonstrating that you are able to interact with the solution.


    1. Tap into the Comment field while the video continues to play. A trigger causes the video to pause automatically, detecting the current position in the video. This allows you as the user to focus on the comment without missing part of the video.

    2. Type a comment about what you see.

    3. Tap the Save button. The comment appears in the bottom portion of the screen and includes both the timestamp for the moment it was made and also the current position in the video. This allows other people viewing the comment to know the precise moment in the video you're commenting about, which saves you the effort of describing this in your comment.

    4. Resume the video and let it play to the end.

    5. Tap on the Play button to the right of your comment. The video starts at the moment where you made your comment.




     

     

    Here's some more information about the script steps, script triggers, and function listed at the top of the screen.


     

    Script steps

     

    • AV Player Play starts the media playing. It provides a range of playback options such as the start position and stop position for playback. You can specify the source of the media: a Layout Object (that is, a container field specified by object name), a Field, or a URL. You also can specify whether the media displays as full screen, displays within the container field, or only plays the audio track (if your source is a URL, you only can choose full screen or audio).


    • AVPlayer Set Options changes the playback settings for media that is already playing. It has similar, though not identical, options to AV Player Play. For example, here you can disable iOS playback controls on the lock screen. You can also set the sequence in which multiple media files should be played.


    • AVPlayer Set Playback State lets you change the playback state (i.e. playing, paused, stopped) of the currently playing media file.



    Script triggers


    • OnObjectAVPlayerChange causes a script to run when the playback state of the media within a specific container field or web viewer changes. This trigger will fire if the playback state is changed by the user, but also if the media stops because it has reached the end, or if the playback state is changed as the result of a script.


    • OnFileAVPlayerChange causes a script to run if a media file is playing from a field or URL, and a user or a script step setting changes the playback state. The following events can activate this script trigger:
      • a user pauses, plays, or stops the media by using the playback controls or gestures
      • a video stops playing at the end of the video
      • the media stops playing because the AVPlayer Set Playback State script step was set to Stopped
      • a video stops playing because the AVPlayer Play script step starts playing a different video

    • OnExternalCommandReceived causes a script to run when the user presses one of the following buttons on the lock screen or on an external device: stop, play, pause, toggle play/pause, play next, play previous, or begin or end seeking forward or backward.



    Function


    • GetAVPlayerAttribute returns a range of attributes for the audio, video, or image file in a container field. These include the media source, the playback state, the presentation (see above), the current playing position, the starting position, the ending position, and many more.