Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

This feature is in development and is not yet released. It will be included in the next point releases of Avalon versions 5 and 6.

 

Avalon Media System provides a simple API interface to allow cross-domain control of a media player embedded in an iframe.

Using this API, client webpages will be able to perform this limited set of operations on the player:

  • Play
  • Pause
  • Toggle auto-replay (loop)
  • Set Current Time (in seconds)
  • Get Current Time (in seconds)

Play, pause, and toggle auto-replay are sent from the parent window without parameters:

postMessage({'command': 'play'}, parent_url)

postMessage({'command': 'pause'}, parent_url)

postMessage({'command': 'toggle_loop'}, parent_url)

SetCurrentTime is sent with params:

postMessage({'command': 'set_offset','offset':123}, parent_url)

GetCurrentTime is sent with no parameters, but requires that a listener be available to hear the server's response, which will look like: data:{'command':'currentTime','currentTime':123}

postMessage({'command': 'get_offset'}, parent_url)

 

Example API Client
<iframe id="player_iframe" title="Wildlife" src="//www.example.com/master_files/g445cd121/embed" width="600" height="50" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
 
<script>
 
  // Send commands to the server
  function send_command(c, params){
    var f = $('#player_iframe');
    var command = params || {};
    command['command']=c;
    f.prop('contentWindow').postMessage(command,f.prop('src'));
  }
 
  // Receive commands from the server
  window.addEventListener('message', function(event) {
    var command = event.data.command;
    if (command=='currentTime') $('#set_offset').val(event.data.currentTime);
  });

</script>
<button onClick="send_command('play')">Play</button>
<button onClick="send_command('pause')">Pause</button>
<button onClick="send_command('toggle_loop')">Toggle Loop</button>
<button onClick="send_command('get_offset')">Get Offset</button>
<button onClick="send_command('set_offset',{'offset':$('#set_offset').val()})">Set Offset</button> 
<input type='text' id='set_offset' size='5'/> [seconds]
  • No labels