Skip to content

Legacy API: AVPlay

Hyojin Kim edited this page Mar 21, 2017 · 24 revisions

For converting AVPlay API of Legacy to TOAST API, please refer to the followings.

If you want more information, please refer to toast.Media and toast.MediaPlugin

play

  • Before

    /* plugin */
    var pluginVideoObj = document.getElementById('pluginPlayer');
    var top = 0;
    var left = 0;
    var width = 100;
    var height = 100;
    pluginVideoObj.SetDisplayArea(top, left, width, height);
    pluginVideoObj.Play('url');
    /* SEF */
    var sef = document.getElementById('sef');
    var top = 0;
    var left = 0;
    var width = 100;
    var height = 100;
    sef.Open('Player', '1.0', 'Player');
    sef.Execute('InitPlayer', url);
    sef.Execute('SetDisplayArea', top, left, width, height);
    sef.Execute('StartPlayback', 0); // Seconds at which playback has to be started
    /* webapis */
    webapis.avplay.getAVPlay(successCB, errorCB);
    
    function successCB(webapisVideoObj) {
        var options = {
            displayRect: { // SRect instance [init()]
                top: 0,
                left : 0,
                width : 100,
                height : 100
            }
        };
        webapisVideoObj.init(options);
        webapisVideoObj.open('url');
        webapisVideoObj.play(successCallback, errorCallback, 0);
        // Seconds at which playback has to be started
    }
  • After

    var media = toast.Media.getInstance();
    media.open('url');
    
    var elContainer = media.getContainerElement();
    elContainer.style.position = 'fixed';
    elContainer.style.left = 0 + 'px';
    elContainer.style.top = 0 + 'px';
    elContainer.style.width = 100 + 'px';
    elContainer.style.height = 100 + 'px';
    document.body.appendChild(elContainer);
    
    media.play();
    //You don't have to call setScreenSaver Method. It is configurated by toast.avplay.

stop

  • Before

    /* plugin */
    pluginVideoObj.Stop();
    /* SEF */
    sef.Execute('Stop');
    /* webapis */
    webapisVideoObj.stop();
  • After

    media.stop();
    //You don't have to call setScreenSaver Method. It is configurated by toast.avplay.

pause

  • Before

    /* plugin */
    pluginVideoObj.Pause();
    /* SEF */
    sef.Execute('Pause');
    /* webapis */
    webapisVideoObj.pause();
  • After

    media.pause();
    //You don't have to call setScreenSaver Method. It is configurated by toast.avplay.

jumpForward

  • Before

    /* plugin */
    pluginVideoObj.JumpForward(10); // number of seconds to be forwarded
    /* SEF */
    sef.Execute('JumpForward', 10); // number of seconds to be forwarded
    /* webapis */
    webapisVideoObj.jumpForward(10); // number of seconds to be forwarded
  • After

    var curPos = media.getCurrentPosition();
    media.seekTo(curPos + 10000);   // The position to seek in milliseconds

jumpBackward

  • Before

    /* plugin */
    pluginVideoObj.JumpBackward(10); // number of seconds to be forwarded
    /* SEF */
    sef.Execute('JumpBackward', 10); // number of seconds to be forwarded
    /* webapis */
    webapisVideoObj.jumpBackward(10); // number of seconds to be forwarded
  • After

    var curPos = media.getCurrentPosition();
    media.seekTo(curPos - 10000);   // The position to seek in milliseconds

listener

  • Before

    /* plugin */
    pluginVideoObj.OnCurrentPlayTime = Player.OnCurrentPlayTime;
    pluginVideoObj.OnBufferingStart = Player.OnBufferingStart;
    pluginVideoObj.OnBufferingComplete = Player.OnBufferingComplete;
    pluginVideoObj.OnRenderingComplete = Player.OnRenderingComplete;     
    pluginVideoObj.OnConnectionFailed = Player.OnConnectionFailed;
    /* SEF */
    VideoElem.OnEvent = function (evet1,data1,data2) {
        switch (evet1) {
            webapis.avplay.CURRENT_PLAYBACK_TIME :
                break;
            webapis.avplay.BUFFERING_START :
                break;
            webapis.avplay.BUFFERING_COMPLETE :
                break;            
            webapis.avplay.RENDERING_COMPLETE :
                break;
            webapis.avplay.CONNECTION_FAILED :
                break;
        }
    }       
    /* webapi */
    webapis.avplay.getAVPlay(successCB, errorCB);
    
    function successCB(webapisVideoObj) {
        var options = {
            bufferingCallback: {
                onbufferingstart : onBufferingStart,
                onbufferingprogress : onBufferingProgress,
                onbufferingcomplete : onBufferingComplete
            },
            playCallback: {
                oncurrentplaytime : onCurrentPlayTime,
                onresolutionchanged : onResolutionChange,
                onstreamcompleted : onStreamComplete,
                onerror : onRederingError
            }
        };
        webapisVideoObj.init(options);
        ...
    }
  • After

     media.setListener({
        onevent: function (evt) {
            switch(evt.type) {
                case "STATE":
                    console.log("Media State changed: " + evt.data.oldState + " -> " + evt.data.state);
    
                    if(evt.data.oldState != 'STALLED' && evt.data.state == 'STALLED'){
                        console.log('Buffering start.');
                    }
                    else if(evt.data.oldState == 'STALLED' && evt.data.state != 'STALLED'){
                        console.log('Buffering complete.');
                    }
                    break;
                case "DURATION":
                    console.log("Media duration updated: " + evt.data.duration + "ms");
                    break;
                case "POSITION":
                    console.log("Media position updated: " + evt.data.position + "ms");
                    break;
                case "BUFFERINGPROGRESS":
                    console.log("Media buffering in progress: " + evt.data.bufferingPercentage + "%");
                    break;
                 case "ENDED":
                    console.log("Media ended");
                    break;
            }
        },
        onerror: function (err) {
            console.error("MediaError occured: " + JSON.stringify(err));
        }
    });

Playback special content

toast MediaPlugin constructor bind to toast.media with option data to be able to playback special content.

    var media= toast.Media.getInstance();
    var mediaPlugin = new toast.MediaPluginHLS();
    media.resetPlugin();
    media.attachPlugin(mediaPlugin);
    media.open('http://mydomain.com/video.m3u8');

MediaPluginHLS
  • Before

    /* plugin */
    pluginVideoObj.Play('url|BITRATES=yourBitRates|STARTBITRATE=yourStartBitRate|SKIPBITRATE=yourSkipBitRate|COMPONENT=HLS');
    /* SEF */
    sef.Execute('InitPlayer', url|BITRATES=yourBitRates|STARTBITRATE=yourStartBitRate|SKIPBITRATE=yourSkipBitRate|COMPONENT=HLS);
    /* webapis */    
    webapis.avplay.getAVPlay(successCB, errorCB);
    
    function successCB(webapisVideoObj) {
        webapisVideoObj.init();
        webapisVideoObj.open("url", {
            adaptive : {
                type : 'HLS',
            }
        });
        webapisVideoObj.play(successCallback, errorCallback, 0);
        // Seconds at which playback has to be started
    }
  • After

    var HLSData = {
        BITRATES : 'yourBitRates',
        STARTBITRATE : "yourStartBitRate",
        SKIPBITRATE : "yourSkipBitRate"
    };
    var mediaPlugin = new toast.MediaPluginHLS(HLSData);

MediaPluginUHD
  • Before

    /* SEF */
    sef.Execute('InitPlayer', 'url');
    sef.Execute('SetUHDResolution', true);
    sef.Execute('StartPlayback', 0); // Seconds at which playback has to be started
    /* webapis */
    webapis.avplay.getAVPlay(successCB, errorCB);
    
    function successCB(webapisVideoObj) {
        webapisVideoObj.init();
        webapisVideoObj.open('url');
        webapisVideoObj.setUHDResolution(true);
        webapisVideoObj.play(successCallback, errorCallback, 0);
        // Seconds at which playback has to be started
    }
  • After

    var mediaPlugin = new toast.MediaPluginUHD();

MediaPluginWideVine
  • Before

    /* plugin */

pluginVideoObj.Play('url|DEVICE_ID=myDeviceId|DEVICET_TYPE_ID=myDeviceTypeId|STREAM_ID=myStreamId|DRM_URL=http://yourDrmUrl.com|I_SEEK=yourI\_SEEK|CUR_TIME=yourCurTime|PORTAL=yourPortal|USER_DATA=yourUserData|COMPONENT=WV'); ```

```js
/* SEF */
sef.Execute('InitPlayer', 'url|DEVICE_ID=myDeviceId|DEVICET_TYPE_ID=myDeviceTypeId|STREAM_ID=myStreamId|DRM_URL=http://yourDrmUrl.com|I_SEEK=yourI\_SEEK|CUR_TIME=yourCurTime|PORTAL=yourPortal|USER_DATA=yourUserData|COMPONENT=WV');
```

```js
/* webapis */    
webapis.avplay.getAVPlay(successCB, errorCB);

function successCB(webapisVideoObj) {
    webapisVideoObj.init();
    webapisVideoObj.open('url', {
        adaptive : {
            type : 'WV',
        }
    });
    webapisVideoObj.play(successCallback, errorCallback, 0);
    // Seconds at which playback has to be started
}
```
  • After

    var wideVineData = {
        DEVICE_ID : 'yourDeviceId', 
        DEVICET_TYPE_ID : 'yourDeviceTypeId', // ex) '60'
        STREAM_ID : 'yourStreamId',
        DRM_URL : 'http://yourDrmUrl.com',
        I_SEEK : 'yourI\_SEEK', // ex) 'TIME'
        CUR_TIME : 'yourCurTime', // ex) 'PTS'
        PORTAL : 'yourPortal',
        USER_DATA : 'yourUserData',
    };
    var mediaPlugin = new toast.MediaPluginWideVine(wideVineData);
    media.attachPlugin(mediaPlugin);
    
    // It is required to set widevine data, before calling "open" method.
    media.open('url');

MediaPluginPlayReady
  • Before

    /* plugin */
    var PROPERTY_TYPE_PLAY_READY_CUSTOM_DATA = 3;
    var PROPERTY_TYPE_PLAY_READY_LICENSE_SERVER = 4;
    pluginVideoObj.SetPlayerProperty(PROPERTY_TYPE_PLAY_READY_CUSTOM_DATA, myCustomData, myCustomData.length);
    pluginVideoObj.SetPlayerProperty(PROPERTY_TYPE_PLAY_READY_LICENSE_SERVER , myLicenseServer, myLicenseServer.length);
    /* SEF */
    var PROPERTY_TYPE_PLAY_READY_CUSTOM_DATA = 3;
    var PROPERTY_TYPE_PLAY_READY_LICENSE_SERVER = 4;
    sef.Execute('InitPlayer', 'url');
    sef.Execute('SetPlayerProperty', PROPERTY_TYPE_PLAY_READY_CUSTOM_DATA, myCustomData, myCustomData.length);
    sef.Execute('SetPlayerProperty', PROPERTY_TYPE_PLAY_READY_LICENSE_SERVER, myLicenseServer, myLicenseServer.length);
    sef.Execute('playbackstart');
    /* webapis */
    webapis.avplay.getAVPlay(successCB, errorCB);
    
    function successCB(webapisVideoObj) {
        webapisVideoObj.init();
        webapisVideoObj.open('url', {
            HEVC : {
                'customData' : myCustomData, 
                'licenseURL' : myLicenseServer
            }
        });
        webapisVideoObj.play(successCallback, errorCallback, 0);
        // Seconds at which playback has to be started
    }
  • After

    var playReadyData = {
        LicenseServer  : 'myLicenseServer',
        CustomData  : 'myCustomData'
    };
    var mediaPlugin = new toast.MediaPluginPlayReady(playReadyData); 
Clone this wiki locally