Skip to content

Instantly share code, notes, and snippets.

@alexeygolev
Forked from gregorymostizky/gist:2892352
Created September 17, 2012 19:24
Show Gist options
  • Save alexeygolev/3739247 to your computer and use it in GitHub Desktop.
Save alexeygolev/3739247 to your computer and use it in GitHub Desktop.
PlayerV3 - Message Bus Usage Example
<html>
<head>
<!-- Load Ooyala Player -->
<script src='http://player.ooyala.com/v3/replace_with_player_branding_id'></script>
</head>
<body>
<!-- Player Placement -->
<div id='playerwrapper' style='width:480px;height:360px;'></div>
<script>
var videoPlayer = OO.Player.create('playerwrapper','video_embed_code', {
onCreate: function(player) {
window.messageBus = player.mb; // save reference to message bus
}
});
// listen for playing event
// it's possible to listen to any event defined in OO.EVENTS or '*' to get all events
window.messageBus.subscribe(OO.EVENTS.PLAYING, 'example', function(eventName) {
alert("Player is now playing!!!");
});
// send play
// it's also possible to send any event to change players behavior
// of course some events require specific parameters to be understood properly
// or maybe be possible to execute only at specific times
window.messageBus.publish(OO.EVENTS.PLAY); // starts playback, you can also use videoPlayer.play() as shortcut
// more advanced use case of blocking events on other events
// let's say we want to block 'pause' function so that when 'pause' is pressed,
// we can display message box asking for confirmation
//
// to do that, we can use addDependent() method
window.messageBus.addDependent(OO.EVENTS.PAUSE, 'user_allowed_pause', 'example', function(eventName) {
// when 'pause' event occurs - i.e. user pressed on pause button in ui (or videoPlayer.pause() was called)
// this code will execute
// ask user for confirmation
CreateConfirmationDialog({
onOk: function() {
window.messageBus.publish('user_allowed_pause'); // after this event is sent, pause is unblocked,
// and player will pause
}
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment