5 Replies Latest reply on Mar 29, 2010 8:36 PM by bringrags

    Interrupting video playback to play an ad


      I looked at the MASTPlugin sample that allows adding pre-roll and post-roll ads using SerialElements. What I am not clear is a way to show ads during the middle of the video stream. In other words, I would want to interrupt the current video, show an ad and resume the video. The video element controls when an ad should be shown. How is this possible with the framework? I am still trying to understand the framework features. Any help is greatly appreciated.

        • 1. Re: Interrupting video playback to play an ad
          bringrags Level 4

          One way to achieve this is to create a ProxyElement that wraps up the video and the mid-roll ad, and dynamically switches between the two (pausing one and playing the other).  You can see such an example here:


          http://opensource.adobe.com/svn/opensource/osmf/trunk/apps/samples/framework/ExamplePlayer /org/osmf/examples/switchingproxy/SwitchingProxyElement.as


          And run it here:




          In this example, the switch happens based on a Timer interval, but in your case you could trigger the switch based on some predefined interval, a cue point, or some other trigger.

          1 person found this helpful
          • 2. Re: Interrupting video playback to play an ad
            venkatrj Level 1

            Brian,  This solution works if the advertising plug-in is controlling the ad and video playback. What I really want is to support the following two use cases. Please let me know your thoughts on this.


            a) The media player controls when an all ads should be shown. The advertising plug-in is only loaded when an ad is to be shown. Ex: At 1 minute into the video, the player has to show an ad that comes from an advertising plug-in. So, it should load the plug-in, tell the plug-in to show the ad and when the ad completes, kill the plug-in and continue the main video. What is the suggested approach for such behavior?


            b) The advertising plug-in wraps the video element and shows the pre-roll but the main video element still has to control when the mid-roll should be shown. So the advertising plug-in shows the pre-roll and waits for the video element to tell when the mid-roll should be shown. After the mid-roll is shown, it should resume the main video and wait until video completes to show the post-roll. The advertising plug-in should also show some overlays while the main video is playing. How can this complex behavior be achieved with a single plug-in?


            Thank you again for your reply.

            • 3. Re: Interrupting video playback to play an ad
              bringrags Level 4

              Great questions.


              a) If the media player has control of the experience, then it should simply load the media from the ad plugin at the moment that it's needed, and insert it into the media presentation.  So the media player would define the composite experience (whether that be a SerialElement with multiple children, or a switching ProxyElement), and insert the MediaElement from the ad accordingly.  Since ad media isn't intrinsically distinct from other media, typically this means that the media player will need to associate some metadata with the ad resource, and the ad plugin will only handle that resource if it has that piece of metadata.  There's no need to unload the plugin -- keep in mind that the loading of a plugin and the loading of the plugin's media are distinct operations.


              So to drill down into your example: I would create a switching ProxyElement (as suggested above) where the primary child is the main video.  At (or just prior to) the one minute mark, the switching ProxyElement would load the MediaElement from the plugin (via MediaFactory.createMediaElement) and switch to it.  (Note that this assumes that the player has loaded the plugin already.)  The key distinction between this and my previous post is that the switching ProxyElement is defined within (and controlled by) the player application, and the plugin simply serves up a single, simple MediaElement.


              b) The generalized statement of this problem is "the player needs to signal to the plugin when to do something".  That's the intent behind MediaElement-level metadata.  The player's MediaElement could signal (via events) the presence or absence of metadata that the plugin can use to decide that an ad needs to be displayed.  So you'd still have a switching ProxyElement at the plugin level, but the plugin wouldn't have control over when to switch (and show the ad).  Instead, it would listen for a metadata event from the primary VideoElement it wraps, and do the switch at that point.  The signal could also come from cue points, which may be a more natural approach.



              These are high-level descriptions of how to tackle these problems, but I've left out much of the detail.  Let me know if this makes sense, and if there are specific areas we should go deeper on.

              • 4. Re: Interrupting video playback to play an ad
                venkatrj Level 1

                Great response Brian. So, do you see all communication to and from the ad media element going through the Metadata instance? And how would the player know when the ad completes in order to resume the main video? Do you suggest creating a PlayTrait that the player monitors or an event dispatched through the metadata that the player can listen for?


                - ven

                • 5. Re: Interrupting video playback to play an ad
                  bringrags Level 4

                  In case (b), metadata can serve as a generic two-way communication mechanism between player and plugin, and that's the recommended approach for custom communication.  But it's often more appropriate for the plugin to gain a reference to the player's MediaElement, and listen in on events like play, pause, seek, complete.


                  The player would know when an ad completes (again, assuming case (b)) based on the complete event coming from the ad's MediaElement.  Of course, this assumes there's some sort of controlling MediaElement (e.g. the switching ProxyElement) which knows what to expect from each child.  (This is a pretty abstract discussion, it might be easier to break this down if you had a specific use case with code.)