Migrating Tizen to TOAST
migrating tizen to toast this topic describes how to convert applications from tizen to toast related info toast media constructor toast mediaplugin constructor toast wiki samples toast to migrate an application from tizen to toast, you must create a toast application using the tizen application as a template, and make the necessary changes in the code some tizen apis do not have a toast equivalent to detect when the application is run on a samsung tv and can use tizen-specific apis, see how to detect platform creating a toast application to migrate a tizen application to toast remove the existing "config xml" file from the application importantthe tizen "config xml" file is not compatible with toast configure the development environment create a toast application, using the existing tizen project as a template use the create command with the --template flag # create toast application using an existing tizen project cordova create mytoastapp --template= / /mytizenapp cd mytoastapp npm install /grunt-cordova-sectv cp -rf /grunt-cordova-sectv/sample/* / npm install cordova platform add browser cordova plugin add /cordova-plugin-toast # run on browser platform cordova build browser cordova emulate browser # prepare for sectv-orsay platform grunt sectv-prepare sectv-orsay # prepare for sectv-tizen platform grunt sectv-prepare sectv-tizen make modifications to the code to use the toast api functionalities in the migrated application remove the following code from the "index html" file <script type="text/javascript" src="$webapis/webapis/webapis js"></script> include the "cordova js" and "toast js" libraries in the "index html" file <script src="cordova js"></script> <script src="toast js"></script> notethe "cordova js" library must be included before the "toast js" library before using the toast apis, you must wait until cordova is fully set up the deviceready event occurs document addeventlistener "deviceready", ondeviceready, false ; function ondeviceready { console log "start the app" ; } migrate functionality from tizen api modules the following section presents examples of how to migrate media playback functionalities to toast for information on how to migrate functionality from other tizen api modules, see the toast wiki when you are ready to test the toast application, build and package it migrating media playback features in toast, media playback functionalities are handled using the toast media and toast mediaplugin constructors notetoast automatically manages the screensaver it does not need to be explicitly managed, such as with the setscreensaver method of the avplay api to open media for playback before webapis avplay open 'url' ; after var media = toast media getinstance ; media open 'url' ; to start media playback 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 ; to stop media playback before webapis avplay stop ; var status = webapis appcommon appcommonscreensaverstate screen_saver_on; webapis appcommon setscreensaver status, function {}, function {} ; after media stop ; to pause media playback before webapis avplay pause ; var status = webapis appcommon appcommonscreensaverstate screen_saver_on; webapis appcommon setscreensaver status, function {}, function {} ; after media pause ; to jump forward during media playback before webapis avplay jumpforward 10000 ; // number of milliseconds to move forward after var curpos = media getcurrentposition ; media seekto curpos + 10000 ; // position to seek to in milliseconds to jump backward during media playback before webapis avplay jumpbackward 10000 ; // number of milliseconds to move backward after var curpos = media getcurrentposition ; media seekto curpos - 10000 ; // position to seek to in milliseconds to implement event listeners 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 ; } } ; to play streaming, 4k, and drm-enabled content, the toast mediaplugin constructor binds to the toast media constructor with specific configuration data for example var media= toast media getinstance ; var mediaplugin = new toast mediapluginhls ; media resetplugin ; media attachplugin mediaplugin ; media open 'http //mydomain com/video m3u8' ; to play http live streaming hls content 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 ; to play 4k uhd video before webapis avplay setstreamingproperty 'set_mode_4k', 'true' ; after var mediaplugin = new toast mediapluginuhd ; to play content with widevine drm 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', for example, '60' stream_id 'yourstreamid', drm_url 'http //yourdrmurl com', i_seek 'youri\_seek', for example, 'time' cur_time 'yourcurtime', for example, 'pts' portal 'yourportal', user_data 'youruserdata', }; var mediaplugin = new toast mediapluginwidevine widevinedata ; media attachplugin mediaplugin ; // widevine data must be set before calling the "open " method media open 'url' ; to play content with playready drm 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 ;