Ticket #1424 (closed feature: fixed)

Opened 22 months ago

Last modified 17 months ago

onBeforePlay() event

Reported by: pablo Owned by:
Priority: High Milestone: Player 5.9
Component: general Keywords:
Cc: Forum thread:

Description (last modified by pablo) (diff)

There are several use cases where it is useful to be able to respond to an event which is fired before the player begins playing a media item. A listener may wish to lock the player and perform an action before the media is loaded, record some analytics data, play a pre-roll ad, or prevent the player from playing entirely by stopping the player.

Typical player event event flow for a single-item playlist should be:

  • onReady
  • onPlaylist
  • onPlaylistItem
  • onBeforePlay
  • onBuffer (oldstate: "IDLE")
  • onBufferFull
  • onPlay (oldstate: "BUFFERING")
  • onComplete
  • onIdle (oldstate: "PLAYING")

Flash Plugin API

Flash plugins wishing to listen for this event should add an event listener for the following event:

MediaEvent.JWPLAYER_MEDIA_BEFOREPLAY (jwplayerMediaBeforePlay)

JavaScript API

Setup block:

jwplayer().setup({
  ...,
  events: {
     onBeforePlay: function(evt) {
         // Event handler
     }
  }
});

Post-setup or JavaScript plugin:

player.onBeforePlay(eventHandler);

Examples

JavaScript API

Prevent a file from playing:

jwplayer('player').setup({
  ...
  events: {
    onBeforePlay: function(evt) {
        if (shouldStopPlayer) {
           this.stop();
        }
    }
  }
});

Flash Plugin API

Alter the current playlist item before playing:

player.addEventListener(MediaEvent.JWPLAYER_MEDIA_BEFOREPLAY, 
   function(event:MediaEvent):void {
      player.playlist.currentItem.file = 'video2.mp4'
   }
);

Change History

comment:1 Changed 22 months ago by pablo

  • Type changed from bug to feature
  • Component changed from embedder to general
  • Description modified (diff)

comment:2 Changed 22 months ago by pablo

  • Milestone set to Player 5.8

comment:3 Changed 21 months ago by pablo

  • Description modified (diff)

comment:4 Changed 19 months ago by pablo

  • Priority set to High

comment:5 Changed 17 months ago by pablo

  • Status changed from new to closed
  • Resolution set to fixed

Implemented in [2032]

Note: See TracTickets for help on using tickets.