Set begin time of Azure Media Player

2.7k views Asked by At

I want to start a AMP(Azure Media Player) HTML5 video on specific time to show specific content of the video.

What does not work is the time to start. The videos always start at 0:00 and then plays nicely to the end. No useful notifications in js console.

I read through some examples and the documentation and this is what I have tried, (note the line myPlayer.currentTime(30);):

Script:

var myPlayer = amp('vid1', { /* Options */
        "nativeControlsForTouch": false,
        autoplay: false,
        controls: true,
        width: "640",
        height: "400",
        poster: ""
    },
    function () {
        myPlayer.src([{
            src: "http://amssamples.streaming.mediaservices.windows.net/91492735-c523-432b-ba01-faba6c2206a2/AzureMediaServicesPromo.ism/manifest",
            type: "application/vnd.ms-sstr+xml"
        }]);
        myPlayer.currentTime(30);
        console.log('Good to go!');
        this.play(); // if you don't trust autoplay for some reason

        // add an event listener
        this.addEventListener('ended', function () {
            console.log('Finished!');
        });
    });

HTML

<video id="vid1" class="azuremediaplayer amp-default-skin">
        <source src="" type="application/vnd.ms-sstr+xml" />
        <p class="amp-no-js">
            To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video
        </p>
    </video>

I have used the following source to set this up. Link to documentation I have used

2

There are 2 answers

0
Magnus Karlsson On BEST ANSWER

Replace the HTML video tag with the following and it will start at the set time. It was setting the source that made currentTime(30); to not run.

<video id="vid1" class="azuremediaplayer amp-default-skin amp-big-play-centered" tabindex="0">  </video>
1
Amit Rajput On

Depending on your scenario, there are two ways you can achieve this.

If your scenario is that you want to start at 30 seconds in, but give the user the ability to view time 0:00-0:30, then setting currentTime after the playing event (after the source is set) will work.

If your scenario is that you want the stream to start at 30 seconds in, but you do not want the viewer to see the first 30 seconds (more like a trimmed or clipped version because perhaps the first 30 seconds is blank content or just a static bumper), you're better off creating a dynamic manifest. With a dynamic manifest, you can trim the start time of your content (and add other filters if desired) in order to have a more precise start time without the need to creating another asset (as it uses the existing asset). Check out the blog for more details about dynamic manifests.