Contents

LivePhotosKit.Player

A player for Live Photos.

Declaration

interface LivePhotosKit.Player

Overview

This class provides a default native control allowing users to play Live Photos.

On a desktop browser, when the user moves the pointer over the native control badge, the video starts playing until the user moves the pointer away from the badge or the video ends. If the user moves the pointer before the video ends, the video stops.

On a mobile device, when the user presses the Live Photo, the video starts playing until the user stops pressing or the video ends.

Player Events

During the life cycle of a player, several events are generated. Adding an event listener to the player allows reaction to these events.

videoload

The player emits a videoload event after the video component of the Live Photo has finished loading but before the minimum number of frames necessary for smooth playback are decoded. Under normal circumstances, the canplay event is emitted after the videoload event. The event handler is then passed an Event object. The Player reference is accessible from the event’s target member.

player.addEventListener('videoload', (ev) => {
    // Handle event.
})

photoload

The player emits a photoload event when the photo component of the Live Photo has finished loading. The event handler is then passed an Event object. The Player reference is accessible from the event’s target member.

player.addEventListener('photoload', (ev) => {
    // Handle event.
})

canplay

The player emits a canplay event when the Player has obtained just enough video frames and is obtaining them quickly enough for smooth playback. The event handler is then passed an Event object. The Player reference is accessible from the event’s target member.

player. addEventListener('canplay', (ev) => {
    // Handle event.
})

ended

The player emits an ended event when playback of the Live Photo has completed. The event handler is then passed an Event object. The Player reference is accessible from the event’s target member.

player.addEventListener('ended', (ev) => {
    // Handle event.
})

error

The player emits an error event when loading of either the photo or video components of the Live Photo has failed. The event handler is then passed an Event object, which has a detail member containing error information. If LivePhotosKit JS cannot interpret an internal exception, the error member of detail will be the exception object. The Player reference may be obtained from the event’s target member.

player.addEventListener('error', (ev) => {
    if (typeof ev.detail.errorCode === 'number') {
        switch (ev.detail.errorCode) {
        case LivePhotosKit.Errors.IMAGE_FAILED_TO_LOAD:
            // Do something
            break;
        case LivePhotosKit.Errors.VIDEO_FAILED_TO_LOAD:
            // Do something
            break;
        }
    } else {
        // Extract Error object.
        console.error(ev.detail.error);
    }
})

Topics

Initializers

Instance Properties

Instance Methods

See Also

Classes