Displaying Media - Media Handlers
  • 15 Oct 2024
  • 1 読む分

Displaying Media - Media Handlers


The content is currently unavailable in Ja - 日本語. You are viewing the default English version.
記事の要約

Templates frequently need to display media (pictures or video) in a controlled manner. This needs support for things like scaling inside a predetermined screen area, and the media, especially video, needs to be “preloaded” so it can be started without delays or glitches once onShift is called. The intrinsic duration of videos can also be useful, so videos are played in full, regardless of the CMS duration value.

The framework includes the Dise.Media namespace or at the root of your reference-namespace with ESM, which contains this functionality. Currently, there is support for pictures and video with auto-detection of type (currently based on file-extension and optional mime-type (if supplied by the template)) as well as optional support for legacy versions of Tizen, which did not support preloading properly and some issues in certain Android releases.

New Media handlers may be added for supporting new media types. This can be done outside of the framework itself and a reference to “your” Media handler is sufficient to get it included in the auto-detection flow.

Here’s a simple template that displays a media file from the CMS. Note that:

  • a reference to “templateframework/framework/Media/Media.ts” is needed - in ESM it is always included.

  • your css/less/sass should include “templateframework/framework/Media/Media.css” (or .less)

  • this template expects the html to contain a fixed size div with the id “MediaContainer”

const DEFAULT_DURATION = 12;

interface CMSData {
    media: {
        url: string;
    }
}

class View extends Dise.SimpleViewBase {

    isDataValid(val: any): val is CMSData {
        return val != null && typeof val === 'object' &&
            typeof val.media?.url === 'string';
    }

    async main(helper: Dise.IDataHelper): Promise<boolean | string | void> {

        if (!this.isDataValid(helper.content))
            throw Error('Data invalid'); 
        // Now, TS knows data is verified to be of the CMSData type.

        const containerE = document.getElementById('MediaContainer');

        let duration = helper.getDuration(DEFAULT_DURATION);
        let mediaHandler: Dise.Media.IMediaHandler;

        [mediaHandler, duration] = await Dise.Media.preloadMedia(containerE, {
            url: helper.content.media.url,
            aspectMode: Dise.Media.AspectMode.letterbox,
            duration: duration,
            hideUntilStart: false
        });
        
        await this.waitForPlay({ 
            duration: duration,
            suggestedNextPreload: duration / 2
        });

        await mediaHandler.start();
    }
}

const ctrl = new Dise.TemplateController(new View());





この記事は役に立ちましたか?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.