# Practical full javascript api examples?

**URL:** <https://community.wowza.com/t/practical-full-javascript-api-examples/49342>\
**Category:** Wowza Developer Dojo\
**Tags:** wowza-player-javascript-api\
**Created:** [August 3, 2017, 3:07am UTC](https://community.wowza.com/t/practical-full-javascript-api-examples/49342 "2017-08-03T03:07:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gary\_Kewley](https://avatars.discourse-cdn.com/v4/letter/g/8797f3/32.png) [@Gary\_Kewley](https://community.wowza.com/u/Gary_Kewley)\
**Post date:** [August 3, 2017, 3:07am UTC](https://community.wowza.com/t/practical-full-javascript-api-examples/49342/1 "2017-08-03T03:07:21Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Michelle\_B](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/michelle_b/32/394_2.png) [@Michelle\_B](https://community.wowza.com/u/Michelle_B)\
**Post date:** [August 23, 2017, 1:24am UTC](https://community.wowza.com/t/practical-full-javascript-api-examples/49342/2 "2017-08-23T01:24:02Z")

</div>

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:

```auto
<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).

```auto
<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
