Skip to content

Tizen API: AVPlay

YongJu Yoon edited this page Oct 28, 2016 · 28 revisions

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

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

####open

  • Before

    webapis.avplay.open('url');
  • After

    var media = toast.Media.getInstance();
    media.open('url');

####play

  • Before

    webapis.avplay.prepare();
    webapis.avplay.setDisplayRect(x, y, width, height);
    webapis.avplay.play();
    var status = webapis.appcommon.AppCommonScreenSaverState.SCREEN_SAVER_OFF;
    webapis.appcommon.setScreenSaver(status, function() {}, function() {});
  • After

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

####stop

  • Before

    webapis.avplay.stop();
    var status = webapis.appcommon.AppCommonScreenSaverState.SCREEN_SAVER_ON;
    webapis.appcommon.setScreenSaver(status, function() {}, function() {});
  • After

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

####pause

  • Before

    webapis.avplay.pause();
    var status = webapis.appcommon.AppCommonScreenSaverState.SCREEN_SAVER_ON;
    webapis.appcommon.setScreenSaver(status, function() {}, function() {});
  • After

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

####jumpForward

  • Before

    webapis.avplay.jumpForward(10000); //The number of milliseconds to be forwarded
  • After

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

####jumpBackward

  • Before

    webapis.avplay.jumpBackward(10000); //The number of milliseconds to be backwarded
  • After

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

####listener

  • Before

    var listener = {
        onbufferingstart: function() {
            console.log('Buffering start.');
        },
        onbufferingprogress: function(percent) {
            console.log('Buffering progress data : ' + data1);
        },
        onbufferingcomplete: function() {
            console.log('Buffering complete.');
        },
        oncurrentplaytime: function(currentTime) {
            console.log('Current Playtime : ' + data1);
        },
        onbufferingcomplete: function() {
            console.log('Buffering complete.');
        },
        onevent: function(eventType, eventData) {
            console.log('event type error : ' + eventType + ', data: ' + eventData);
        },
        onerror: function(eventType) {
            console.log('event type error : ' + eventType);
        },
        onsubtitlechange: function(duration, text, data3, data4) {
            console.log('Subtitle Changed.');
        },  
        ondrmevent: function(drmEvent, drmData) {
            console.log('DRM callback: ' + drmEvent + ', data: ' + drmData);
        },
        onstreamcompleted: function() {
            console.log('Stream Completed');
        }
     }
    webapis.avplay.setListener(listener);
  • After

     media.setListener({
        onevent: function (evt) {
            switch(evt.type) {
                case 'STATE':
                    console.log('Media State changed: ' + evt.data.oldState + ' -> ' + evt.data.state);
                    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 + '%');
                    if(evt.data.bufferingPercentage >= 100) {
                        console.log('Buffering completed');
                    }
                    break;
                 case 'ENDED':
                    console.log('Media ended');
                    break;
            }
        },
        onerror: function (err) {
            console.error('MediaError occured: ' + JSON.stringify(err));
        }
    });

####Playback special content(setStreaming / setDRM) 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();
    // you do not need to call 'resetPlugin API' any more, because We process in advance.
    // media.resetPlugin(); 
    media.attachPlugin(mediaPlugin);
    media.open('http://mydomain.com/video.m3u8');
setStreamingProperty
MediaPluginHLS
  • Before

    webapis.avplay.setStreamingProperty('ADAPTIVE_INFO', 'BITRATES=yourBitRates|STARTBITRATE=yourStartBitRate|SKIPBITRATE=yourSkipBitRate');
  • After

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

    webapis.avplay.setStreamingProperty('SET_MODE_4K', 'TRUE');
  • After

    var mediaPlugin = new toast.MediaPluginUHD();
MediaPluginWideVine
  • Before

    webapis.avplay.open('url');
    
    var wideVineData = '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'
    webapis.avplay.setStreamingProperty('WIDEVINE', wideVineData);
    
    webapis.avplay.prepare();
  • 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');
setDrm
privilege

<tizen:privilege name="http://developer.samsung.com/privilege/drmplay"/>

MediaPluginPlayReady
  • Before

    var playReadyData = {
        LicenseServer  : 'myLicenseServer',
        CustomData  : 'myCustomData'
    };
    webapis.avplay.setDrm('PLAYREADY', 'SetProperties', JSON.stringify(playReadyData));
  • After

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