Wowza Community

Practical full javascript api examples?

Hi,

Is there full javascript api examples for Wowza Player? I’ve been playing around with the api without much success.

It would be helpful if there were full javascript api examples, such as stopping the video playback after 30 seconds of play or fallback to a another video if the live streams times out.

Thank you!

Hi Gary,

This has been addressed in a ticket (#241916), but I wanted to post it here as well for others.
Example to stop player instance after 30 seconds of play:

<script type="text/javascript">
var myPlayer = WowzaPlayer.create('playerElement',
    {
  "license":yourKey,
  "sourceURL":yourUrl
    }
);
playheadTimeListener = function ( playheadTimeEvent ) {
    console.log('Time: ' + playheadTimeEvent.time);
 if (playheadTimeEvent.time >= 30000) {
  myPlayer.removeOnPlayheadTime( playheadTimeListener );
  myPlayer.finish();
 }
};
myPlayer.onPlayheadTime( playheadTimeListener );
</script>

Example to create a different player instance if the first one reports an error (the live stream is unavailable).

<script type="text/javascript">
var myPlayer = WowzaPlayer.create('playerElement',
    {
  "license":yourKey,
  "sourceURL":yourLiveStream
    }
);
errorListener = function ( errorEvent ) {
    console.log('Message: ' + errorEvent.error);
 var myPlayer = WowzaPlayer.create('playerElement',
    {
  "license":yourKey,
  "sourceURL":yourVodStream,
  "autoPlay":true  
    }
);
};
myPlayer.onError( errorListener );
</script>

Michelle