Wowza Community

Catch wowza player play event for updating token

Hi,
I have a problem with a secure token in a player. In my case, my code looks as follows:

<div id="wowza_player" ></div>
<script type="text/javascript">
var myPlayer = WowzaPlayer.create("wowza_player",
    {
    "license":"PLAY2-49nKb-TjeXx-xxxxxx-xxxxxx-xxxxxx",
    "sources":[{
    "sourceURL":"https://cdn3.wowza.com/1/xxxxxxx/xxxxxxx/hls/live/playlist.m3u8?<?php echo $token;?>"
    },
    {
    "sourceURL":""
    }],
    "title":"xxxxxxxxxxxxxxx",
    "description":"",
    "autoPlay":true,
    "mute":false,
    "volume":75,
    "posterFrameURL":"https://xxxxxxxxxx.de/player_preview.jpg",
    "withCredentials":"true"
    }

);

</script>

As you can see, the security token is generated with PHP. The token is valid for 3 seconds.
Usually the autoplay function is active. But if the browser is disabling the autoplay and the user pressed the big or small play button, the token is not valid any more.
Now, I want to update the sourceURL when the user clicks play.
I tried this code, but it doesn´t work:

myPlayer.onPlay( updateSecret(); );

So, what is the right code for catching the play event?

Thanks in advance.

We don’t have a straightforward way to do it. onPlay() event that you are attaching, that gets called once player starts playback. Since on first play button click, it’s erroring for you, you needs to listen to onError() event. Now in that process you need to reset the player. You can destroy the player and create it again, and this time autoPlay should work (Since user already interacted once). There is another way, where you can create a custom object of “sources” and set it on the Player in onError(), but it’s not a documented method and it will require little bit of work to create a sample and test it.

You may want to see if one of our Consultants wants to help you build that in the Hire A Consultant forum here.

Thanks for the reply.
But in my case, nothing of the Event instance methods are working.
Just to make clear:
This reference is the right one for the Wowza player builder ?