Stop or pause after a specified time with the Wowza Player JavaScript API

Wowza Player is sunset and should only be used with existing Ultra-Low Latency (ULL) streams until that technology is also sunset.

Learn how to use the Wowza™ Player JavaScript API to control playback. In this specific example, see how to pause or end playback in Wowza Player after a specified length of time.

Example HTML

Note: See the Wowza Player JavaScript API Reference to get started with the Wowza Player API.

In the following code example, we use the onPlayheadTime method to attach an event listener that’s called at 500-millisecond intervals throughout playback. At each interval, the playheadTimeListener callback function prints the current playhead time (in milliseconds) to the console. If the current playhead time is greater than or equal to 30 seconds, the event listener is removed and the stream either stops or pauses, depending on whether you use the finish or pause methods.

Note: The pause method is only applicable for VOD streams and live nDVR streams, not live streams without nDVR.
  <script type="text/javascript" src="//"></script>

<div id="playerElement" style="width:100%; height:0; padding:0 0 56.25% 0"></div>
<script type="text/javascript">
  var myPlayer = WowzaPlayer.create('playerElement',

  //Stop the player at or after 30 seconds 
  playheadTimeListener = function ( playheadTimeEvent ) {
    console.log('Time: ' + playheadTimeEvent.time);
    if (playheadTimeEvent.time >= 30000) {

    myPlayer.removeOnPlayheadTime( playheadTimeListener );
    //Can alternatively use myPlayer.pause(); for VOD or live nDVR streams to pause the stream.

  //Listen for every 500 milliseconds, then execute the callback function above.