To use Samsung Product API, <script type="text/javascript" src="$WEBAPIS/webapis/webapis.js"></script> Should be loaded in index.html
To use Samsung Product API,
<script type="text/javascript" src="$WEBAPIS/webapis/webapis.js"></script>
Should be loaded in index.html
This module defines the multimedia player functionalities provided by the Tizen Samsung TV Product API.
Since : 2.3
Product : TV, AV, B2B
Specifies the player state.
enum AVPlayPlayerState { "NONE", "IDLE", "READY", "PLAYING", "PAUSED" };
The following values are supported
Specifies display modes.
enum AVPlayDisplayMode { "PLAYER_DISPLAY_MODE_LETTER_BOX", "PLAYER_DISPLAY_MODE_FULL_SCREEN", "PLAYER_DISPLAY_MODE_AUTO_ASPECT_RATIO" };
Specifies buffering scenarios.
enum AVPlayBufferOption { "PLAYER_BUFFER_FOR_PLAY", "PLAYER_BUFFER_FOR_RESUME" };
Specifies buffer size units.
enum AVPlayBufferSizeUnit { "PLAYER_BUFFER_SIZE_IN_SECOND" };
Remark :
Specifies parameters for various streaming protocols, such as HTTP, MMS, and adaptive streaming (Smooth Streaming, HLS, and MPEG-DASH).
enum AVPlayStreamingPropertyType { "COOKIE", "USER_AGENT", "PREBUFFER_MODE", "ADAPTIVE_INFO", "LISTEN_SPARSE_TRACK", "IS_LIVE", "AVAILABLE_BITRATE", "GET_LIVE_DURATION", "CURRENT_BANDWIDTH", "USE_VIDEOMIXER", "SET_MIXEDFRAME", "PORTRAIT_MODE" };
Specifies DRM systems supported by the player.
enum AVPlayDrmType { "PLAYREADY", "VERIMATRIX", "WIDEVINE_CDM" };
Specifies various DRM operations.
enum AVPlayDrmOperation { "SetProperties", "InstallLicense", "ProcessInitiator", "widevine_license_data" };
Specifies stream types supported by the player.
enum AVPlayStreamType { "VIDEO", "AUDIO", "TEXT" };
Specifies the player error messages.
enum AVPlayError { "PLAYER_ERROR_NONE", "PLAYER_ERROR_INVALID_PARAMETER", "PLAYER_ERROR_NO_SUCH_FILE", "PLAYER_ERROR_INVALID_OPERATION", "PLAYER_ERROR_SEEK_FAILED", "PLAYER_ERROR_INVALID_STATE", "PLAYER_ERROR_NOT_SUPPORTED_FILE", "PLAYER_ERROR_NOT_SUPPORTED_FORMAT", "PLAYER_ERROR_INVALID_URI", "PLAYER_ERROR_CONNECTION_FAILED", "PLAYER_ERROR_GENEREIC" };
Specifies player events.
enum AVPlayEvent { "PLAYER_MSG_NONE", "PLAYER_MSG_RESOLUTION_CHANGED", "PLAYER_MSG_BITRATE_CHANGE", "PLAYER_SPARSE_TRACK_DETECT", "PLAYER_STREAMING_EVENT", "PLAYER_MSG_HTTP_ERROR_CODE", "PLAYER_MSG_DRM_CHALLENGE_DATA", "PLAYER_MSG_CUE_TAG_INFO" };
Defines a dictionary for streaming video, audio and subtitle information for various streaming scenarios.
dictionary AVPlayStreamInfo { unsigned long index; AVPlayStreamType type; DOMString extra_info; };
Defines a dictionary for subtitle attributes.
dictionary AVPlaySubtitleAttribute { DOMString attr_type; long start_pos; long stop_pos; };
Defines a WebApi object instance of the Tizen Samsung TV Product API. The webapis.AVPlay object enables access to AVPlay API functionality.
[NoInterfaceObject] interface AVPlayManagerObject { readonly attribute AVPlayManager avplay; };
WebApi implements AVPlayManagerObject;
Provides methods for the AVPlay functionalities.
[NoInterfaceObject] interface AVPlayManager { void open(DOMString url); void close(); void prepare(); void prepareAsync(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback); void setDisplayRect(unsigned long x, unsigned long y, unsigned long width, unsigned long height); void play(); void seekTo(long milliseconds, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback); void stop(); AVPlayPlayerState getState(); void pause(); void jumpForward(long milliseconds, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback); void jumpBackward(long milliseconds, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback); unsigned long getDuration(); unsigned long getCurrentTime(); void setTimeoutForBuffering(unsigned long seconds); void setBufferingParam(AVPlayBufferOption option, AVPlayBufferSizeUnit unit, unsigned long amount); void setSpeed(long playbackSpeed); void setListener(AVPlayPlaybackCallback playbackCallback); DOMString setDrm(AVPlayDrmType drmType, AVPlayDrmOperation drmOperation, DOMString jsonParam); DOMString getUID(AVPlayDrmType drmType); void setSoundAnalysisListener(AVPlaySoundAnalysisCallback soundAnalysisCallback); void unsetSoundAnalysisListener(); void setSilentSubtitle(boolean onoff); void setExternalSubtitlePath(DOMString filePath); void setSubtitlePosition(long position); void setDisplayMethod(AVPlayDisplayMode displayMode); void setSelectTrack(AVPlayStreamType trackType, long trackIndex); AVPlayStreamInfo[] getCurrentStreamInfo(); AVPlayStreamInfo[] getTotalTrackInfo(); void setStreamingProperty(AVPlayStreamingPropertyType propertyType, DOMString propertyParam); DOMString getStreamingProperty(AVPlayStreamingPropertyType propertyType); DOMString getVersion(); void suspend(); void restore(optional DOMString? URL, optional unsigned long? resumeTime, optional boolean? bPrepare); void restoreAsync(optional DOMString? URL, optional unsigned long? resumeTime, optional boolean? bPrepare, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback); };
Instantiates the player object with a content URL as the input parameter.
void open(DOMString url);
Constraint :
Parameters :
Exceptions :
Code Example :
try { webapis.avplay.open(url); } catch (e) { console.log(e) }
Destroys the player object.
void close();
try { webapis.avplay.close(); } catch (e) { console.log(e) }
Prepares the media player for playback synchronously. The player must already be created with a valid URI.
void prepare();
try { webapis.avplay.prepare(); } catch (e) { console.log(e) }
Prepares the media player for playback asynchronously. This method is preferred over prepare because it returns immediately and does not block the application thread during preparation. When preparation is successful, the success callback is returned and the player is in READY state. If preparation fails, the error callback returns the error value. When prepareAsync is used with "PREBUFFER_MODE", successCallback is invoked when prebuffering is complete, instead of when preparation is complete.
void prepareAsync(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
webapis.avplay.prepareAsync(successCallback, errorCallback);
Sets the display area for video content playback. The 4 parameters specify the left side, top, window width, and window height based on a 1920 x 1080 resolution screen, regardless of the actual application resolution.
void setDisplayRect(unsigned long x, unsigned long y, unsigned long width, unsigned long height);
try { webapis.avplay.setDisplayRect(0, 0, 1920, 1080); } catch (e) { console.log(e) }
Starts stream playback, or resumes stream playback after pause.
void play();
try { webapis.avplay.play(); } catch (e) { console.log(e) }
Skips playback to a specific timestamp. For HTTP streaming, this method is successful even when the specified timestamp is invalid. The internal player automatically resets an out-of-range value to an in-range one.
void seekTo(long milliseconds, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
try { webapis.avplay.seekTo(10000,successCallback, errorCallback); } catch (e) { console.log(e) } // for live cases, get the live duration as : var StartTime = webapis.avplay.getStreamingProperty("GET_LIVE_DURATION").split('|')[0]; var EndTime = webapis.avplay.getStreamingProperty("GET_LIVE_DURATION").split('|')[1]; // seekpoint must be between StartTime and Endtime.
Stops the player. Call this function after the video finishes playing.
void stop();
try { webapis.avplay.stop(); } catch (e) { console.log(e) }
Retrieves the current player state.
AVPlayPlayerState getState();
Return Value :
var BRet = webapis.avplay.getState();
Pauses playback. If this method is called successfully, current time updates are stopped.
void pause();
try { webapis.avplay.pause(); } catch (e) { console.log(e) }
Skips playback forward by a specific amount of time. The player state is unchanged. Passing the optional callbacks is recommended. For best performance, ensure that the previous call to this API was successful. For HTTP streaming, this method is successful even when the resulting timestamp is invalid. The internal player automatically resets an out-of-range value to an in-range one.
void jumpForward(long milliseconds, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
webapis.avplay.jumpForward(5000,successCallback, errorCallback);
Skips playback backward by a specific amount of time. The player state is unchanged. For HTTP streaming, this method is successful even when the resulting timestamp is invalid. The internal player automatically resets an out-of-range value to an in-range one.
void jumpBackward(long milliseconds, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
webapis.avplay.jumpBackward(5000,successCallback, errorCallback);
Retrieves the total media duration.
unsigned long getDuration();
duration = calcPlaytime(webapis.avplay.getDuration()) function calcPlaytime(totalMilisec) { var Hours = Math.floor(totalMilisec/3600000); var Minutes = Math.floor((totalMilisec - (Hours3600000)) / 60000); var Seconds = Math.floor((totalMilisec - (Hours3600000) - (Minutes60000)) / 1000); var Milisec = totalMilisec - (Hours3600000) - (Minutes60000) - (Seconds1000); return { Hours: Hours, Minutes: Minutes, Seconds: Seconds, milisec: Milisec, totalMilisec: totalMilisec } }
Retrieves the current playback time.
unsigned long getCurrentTime();
var CurrentPlayTime = webapis.avplay.getCurrentTime();
Sets the stream buffering timeout. When the specified amount of time has passed, the onbufferingcomplete callback is invoked, irrespective of buffering progress. If not set using this method, the default buffer size is 32MB or 10 seconds of playable data, and 20 seconds time-out.
void setTimeoutForBuffering(unsigned long seconds);
webapis.avplay.setTimeoutForBuffering(10);
Sets the buffer size for the play and resume scenarios. The time buffer size must be at least 4 seconds. For example, if a 10 second buffer size is set, playback can only start or resume after 10 seconds of media has accumulated in the buffer. Play scenarios include user-initiated streaming playback and whenever media playback is starting for the first time. Resume scenarios include resuming playback after pause or seek operations, or when lack of data causes playback rebuffering.
void setBufferingParam(AVPlayBufferOption option, AVPlayBufferSizeUnit unit, unsigned long amount);
// For the initial buffering webapis.avplay.setBufferingParam("PLAYER_BUFFER_FOR_PLAY","PLAYER_BUFFER_SIZE_IN_SECOND", 5); // 5 is in seconds // For the rebuffering webapis.avplay. setBufferingParam("PLAYER_BUFFER_FOR_RESUME","PLAYER_BUFFER_SIZE_IN_SECOND", 15); // 15 is in seconds
Sets the current playback rate. Positive parameter values play the media forwards, while negative values cause the media to play in reverse. The range of valid playback rates depends on the streaming protocol. If the input parameter is out of range, the player returns the PLAYER_ERROR_INVALID_PARAMETER flag.
void setSpeed(long playbackSpeed);
try { webapis.avplay.setSpeed(2); } catch (e) { console.log(e) }
Sets asynchronous callback methods for player information notifications, such as buffering progress, player information, playback mode, and DRM mode information.
void setListener(AVPlayPlaybackCallback playbackCallback);
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); }, onerrormsg: function(eventType,eventMsg) { console.log("event type error : " + eventType); console.log("event Message : " + eventMsg); }, 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);
Updates the DRM information, such as SetProperties. You can change the DRM mode and run the control feature. The AVPlayDrmOperation and jsonParam parameters depend on the DRM type. Please refer to the specification (https://developer.samsung.com/tv/develop/specifications/general-specifications) for the supported DRM.
DOMString setDrm(AVPlayDrmType drmType, AVPlayDrmOperation drmOperation, DOMString jsonParam);
Privilege Level : Public
Privilege : http://developer.samsung.com/privilege/drmplay
// Implementing DRM support // 1. PlayReady example: Setting license server and custom data // 1.1 PlayReady with GenChallenge (supported since TIzen 4.0) var Listener = { ondrmevent: function(drmType, drmData) { if(drmData.name === 'Challenge') { // take drmData.challenge to obtain license data. } } } webapis.avplay.setListener(Listener); var appdata={DeleteLicenseAfterUse:true,GetChallenge:true,LicenseServer:"http://license.company.com", CustomData:"mycustom"}; webapis.avplay.setDrm("PLAYREADY", "SetProperties", JSON.stringify(appdata)); // The avplay will configure and provide challenged data through ondrmevent() callback. // Once challenge data is received, the application should first decode challenge data using base64, and obtain license from the license server. var license_data;// After obtaining license data, encode it using base64 and save into this 'license_data'. webapis.avplay.setDrm("PLAYREADY", "InstallLicense", license_data); // 1.2. PlayReady without GenChallenge var appdata={DeleteLicenseAfterUse:true, LicenseServer:"http://license.company.com", CustomData:"mycustom"}; webapis.avplay.setDrm("PLAYREADY", "SetProperties", JSON.stringify(appdata)); // 2. Verimatrix example: Initializing Verimatrix DRM // Application should call GetUID only once and save it for further use, after every open API GetUID need not be called. if (true) { // Since Tizen version 5.0 DOMString Verimatrix_UID = webapis.avplay.getUID("VERIMATRIX"); } else { // Before Tizen version 5.0 webapis.avplay.setDrm( "VERIMATRIX", "GetUID", ""); } // After open application should follow following sequence var DrmParam = {}; DrmParam.CompanyName ="MyCompany"; DrmParam.IPTV="public2.verimatrix.com"; DrmParam.Web="public-ott-nodrm.verimatrix.com:80"; if (true) { // Since Tizen version 5.0 webapis.avplay.setDrm( "VERIMATRIX", "SetProperties", JSON.stringify(DrmParam)); } else { // Before Tizen version 5.0 webapis.avplay.setDrm( "VERIMATRIX", "Initialize", JSON.stringify(DrmParam)); } // 3. Widevine Modular example var sessionId; var Listener = { ondrmevent: function(drmType, drmData) { if(drmData.name === 'Challenge') { sessionId = drmData.session_id; // take drmData.challenge and drmData.serverurl to obtain license data. } } } webapis.avplay.setListener(Listener); var DrmParam = {}; // Sample session value; App must set there own session id. DrmParam.AppSession = "test-session"; DrmParam.DataType = "MPEG-DASH"; if (true) { // Since Tizen version 5.0 webapis.avplay.setDrm("WIDEVINE_CDM", "SetProperties", JSON.stringify(DrmParam)); } else { // Before Tizen version 5.0 webapis.avplay.setDrm("WIDEVINE_CDM", "Initialize", ""); webapis.avplay.setDrm("WIDEVINE_CDM", "widevine_app_session", DrmParam.AppSession); webapis.avplay.setDrm("WIDEVINE_CDM", "widevine_data_type", DrmParam.DataType); } // The avplay will configure and provide challenged data and session id through ondrmevent() callback. // Once challenge data is received, the application should first decode challenge data using base64, and obtain license from the license server. var license_data;// After obtaining license data, encode it using base64 and save into this 'license_data'. var LicenseParam = sessionId + "PARAM_START_POSITION" + license_data + "PARAM_START_POSITION"; webapis.avplay.setDrm("WIDEVINE_CDM", "widevine_license_data", LicenseParam); //In Tizen 5.0 onwards use EME_WIDEVINE_CDM instead of using WIDEVINE_CDM
Gets the device UID. The input would be the drm type.
DOMString getUID(AVPlayDrmType drmType);
var verimatrixUID = webapis.avplay.getUID("VERIMATRIX"); //Verimatrix example: Retrieving the Verimatrix UID
Retrieves the audio spectrum analysis result every 30 ms. You can use it for an equalizer effect video or in a PartyTV application. The spectrum is analyzed across an array of 31 bands, of which Bands[14] ~ Bands[18] generally have the largest values.
void setSoundAnalysisListener(AVPlaySoundAnalysisCallback soundAnalysisCallback);
Deprecated : 2.4
webapis.avplay.setSoundAnalysisListener(soundAnalysisListener); function soundAnalysisListener(dataArray) { // Listener registered to and receiving data from AVPlay var BarHeight = 0; var AbsValue = 0; var Threshold = 70; for (var I = 0; I < dataArray.length; I++) { AbsValue = Math.abs(dataArray[I]); if (AbsValue > Threshold) { BarHeight = Main.barContainerHeight; } else { BarHeight = Math.round((AbsValue/Threshold)Main.barContainerHeight); } if (BarHeight == 0) BarHeight = 1; document.getElementById('frequencyBar' + I).style.height = BarHeight + 'px'; } console.log("Sound analysis: " + dataArray.toString()); }
Unregisters the sound analysis listener.
void unsetSoundAnalysisListener();
webapis.avplay.unsetSoundAnalysisListener();
Enables or disables external subtitles.
void setSilentSubtitle(boolean onoff);
webapis.avplay.setSilentSubtitle(true);
Sets the local path for the external subtitle file. Only absolute local paths are supported. If the subtitle file is stored remotely, you must first download the file to local storage, and pass the absolute local path.
void setExternalSubtitlePath(DOMString filePath);
webapis.avplay.setExternalSubtitlePath(uri);
Adjusts external subtitle synchronization with the audio and video.
void setSubtitlePosition(long position);
webapis.avplay.setSubtitlePosition(position_millisec);
Sets the video screen mode in the specified display area.
void setDisplayMethod(AVPlayDisplayMode displayMode);
webapis.avplay.setDisplayMethod("PLAYER_DISPLAY_MODE_FULL_SCREEN");
Switches audio or subtitle tracks during playback.
void setSelectTrack(AVPlayStreamType trackType, long trackIndex);
var totalTrackInfo = webapis.avplay.getTotalTrackInfo(); for (var i=0; i<totalTrackInfo.length; i++) { if(totalTrackInfo.type == 'TEXT') { console.log('Find subtitle track.'); console.log('subtitle track index is ' + totalTrackInfo.index); console.log('subtitle track language is ' + totalTrackInfo.extra_info.track_lang); } } // Choose subtitle track index 2 webapis.avplay.setSelectTrack('TEXT',2);
Retrieves the currently-playing video, audio, or subtitle stream information, and notifies that a stream is playing.
AVPlayStreamInfo[] getCurrentStreamInfo();
var StreamInfo = webapis.avplay.getCurrentStreamInfo(); var Text = ''; for (var I = 0; I < StreamInfo.length; I++) { Text += 'index: ' + StreamInfo[I].index + ''; Text += 'type: ' + StreamInfo[I].type + ''; Text += 'extra_info: ' + StreamInfo[I].extra_info + ''; } // All streams have extra_info as a JSONString. // video extra_info example : "{fourCC:"H264","Width":"1920","Height":"1080","Bit_rate":" 477000"}" // audio extra_info example : "{"language":"en","channels":"2","sample_rate":"44100","bit_rate":"96000","fourCC":"AACL"}" // text(subtitle) extra_info example : "{"track_num":"0","track_lang":"en","subtitle_type":"-1","fourCC":"TTML"}" // If the stream is invalid, the DOMString is null and the index value is -1.
Retrieves the currently-playing stream information.
AVPlayStreamInfo[] getTotalTrackInfo();
var TrackInfo = webapis.avplay.getTotalTrackInfo(); var Text = 'type of track info: ' + typeof TrackInfo + ''; Text += 'length: ' + TrackInfo.length + ''; for (var I = 0; I < TrackInfo.length; I++) { Text += 'index: ' + TrackInfo[I].index + ''; Text += 'type: ' + TrackInfo[I].type + ''; Text += 'extra_info: ' + TrackInfo[I].extra_info + ''; }
Sets specific feature values for HTTP, MMS, or specific streaming engine (Smooth Streaming, HLS, DASH, DivX Plus Streaming, or Widevine). The available streaming properties depend on the streaming protocol or engine. Use the CUSTOM_MESSAGE property for streaming engine or CP-specific settings.
void setStreamingProperty(AVPlayStreamingPropertyType propertyType, DOMString propertyParam);
//Smooth Streaming example: var BitRateString = "BITRATES=5000~10000|STARTBITRATE=HIGHEST|SKIPBITRATE=LOWEST"; webapis.avplay.setStreamingProperty("ADAPTIVE_INFO", BitRateString); //Prebuffer mode example: //Player1 => Playback of Main Content //Player2 => Playback of advertisement (Buffered the ad content before playback). Player1 = webapis.avplaystore.getPlayer(); Player2 = webapis.avplaystore.getPlayer(); Player1.open('http://www.example.com/example_1.mp4'); Player1.setDisplayRect(x, y, width, height); Player1.prepare(); Player1.play(); Player2.open('http://www.example.com/example_2.mp4'); Player2.setStreamingProperty("PREBUFFER_MODE", "5000"); Player2.setDisplayRect(x, y, width, height); Player2.prepare(); Player1.stop(); Player2.play(); //User-agent example: webapis.avplay.setStreamingProperty("USERAGENT", "samsungsmooth-agent/1.1"); Setting resolution information for HLS/DASH webapis.avplay.setStreamingProperty("ADAPTIVE_INFO", "FIXED_MAX_RESOLUTION=7680X4320"); //Mixer example: Player1 = webapis.avplaystore.getPlayer(); Player2 = webapis.avplaystore.getPlayer(); Player1.open(url1); Player1.setStreamingProperty("USE_VIDEOMIXER", ""); //enable video mixer Player1.setDisplayRect(17, 17, 932, 1044); //configure the position (coordinates) of this player instance, used for SET_MIXEDFRAME Player1.prepare(); Player1.setStreamingProperty("SET_MIXEDFRAME", ""); //now sets position of mixed frame Player1.play(); Player2.open(url2); Player2.setStreamingProperty("USE_VIDEOMIXER", ""); //enable video mixer Player2.setDisplayRect(973, 17, 932, 1044); //configure the position (coordinates) of this player instance, used for SET_MIXEDFRAME Player2.prepare(); Player2.setStreamingProperty("SET_MIXEDFRAME", ""); //now sets position of mixed frame Player2.play();
Retrieves a specific property value obtained by the streaming engine (Smooth Streaming, HLS, DASH, or Widevine).
DOMString getStreamingProperty(AVPlayStreamingPropertyType propertyType);
var Text = 'AVAILABLE_BITRATE: ' + webapis.avplay.getStreamingProperty ("AVAILABLE_BITRATE") ; Text += 'CURRENT_BANDWIDTH: ' + webapis.avplay.getStreamingProperty ("CURRENT_BANDWIDTH") + ''; Text += 'IS_LIVE: ' + webapis.avplay.getStreamingProperty ("IS_LIVE") +''; @code var StartTime = webapis.avplay.getStreamingProperty("GET_LIVE_DURATION").split('|')[0]; var EndTime = webapis.avplay.getStreamingProperty("GET_LIVE_DURATION").split('|')[1]; if (StartTime > targetSeekTime) { if (EndTime < targetSeekTime) { webapis.avplay.seekTo(targetSeekTime); //ms } }
Retrieves the AVPlay version.
DOMString getVersion();
var Version = webapis.avplay.getVersion();
Pauses the player state when the application is sent to the background. Saves the current statistics for the ongoing playback session.
void suspend();
document.addEventListener("visibilitychange", function() { if(document.hidden){ // Something you want to do when application is paused. console.log("lifecycle [pause]"); webapis.avplay.suspend(); } else { // Something you want to do when application is resumed. console.log("lifecycle [resume]"); webapis.avplay.restore(); } });
During multitasking, restores the player state when the application is resumed. For live streaming or DRM-encrypted content playback, you must check whether the streaming URL has changed or the DRM session or license has expired, and specify the new URL and DRM information as needed.
void restore(optional DOMString? URL, optional unsigned long? resumeTime, optional boolean? bPrepare);
document.addEventListener("visibilitychange", function() { if(document.hidden){ // Something you want to do when application is paused console.log("lifecycle [pause]"); webapis.avplay.suspend(); } else { // Something you want to do when application is resumed console.log("lifecycle [resume]"); webapis.avplay.restore(url, 0, false); } });
During multitasking, restores the player state when the application is resumed. restoreAsync is an asynchronous interface. Other API, restore is a synchronous interface which blocks the application thread. This method is preferred over restore because it returns immediately and does not block the application thread during its restoration. When player is restored successful, the success callback is returned and player resumed the playback from the restored playback position, state, properties etc. If restoration fails, the error callback returns the error value. Application is required to make further calls to avplay on its success or failure callback happens. For live streaming or DRM-encrypted content playback, you must check whether the streaming URL has changed or the DRM session or license has expired, and specify the new URL and DRM information as needed.
void restoreAsync(optional DOMString? URL, optional unsigned long? resumeTime, optional boolean? bPrepare, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
document.addEventListener("visibilitychange", function() { if(document.hidden){ // Something you want to do when application is paused console.log("lifecycle [pause]"); webapis.avplay.suspend(); } else { // Something you want to do when application is resumed console.log("lifecycle [resume]"); try { var successCallback = function() { console.log("success"); } var errorCallback = function(err) { throw new Error('Error:' + err.name); } webapis.avplay.restoreAsync(url, 0, false, successCallback, errorCallback); } catch (e) { console.log(e) } } });
Defines callbacks for buffering and playback notifications.
[Callback=FunctionOnly, NoInterfaceObject] interface AVPlayPlaybackCallback { void onbufferingstart(); void onbufferingprogress(unsigned long percent); void onbufferingcomplete(); void oncurrentplaytime(unsigned long currentTime); void onstreamcompleted(); void onevent(AVPlayEvent eventid, DOMString data); void onerror(AVPlayError eventid); void onerrormsg(AVPlayError eventid, DOMString errorMsg); void ondrmevent(AVPlayDrmType type, drmData data); void onsubtitlechange(DOMString duration, DOMString subtitles, DOMString type, AVPlaySubtitleAttribute[] attributes); };
Callback method for asynchronous buffering started notifications.
void onbufferingstart();
onbufferingstart: function() { console.log("Buffering start."); }
Callback method for asynchronous buffering progress notifications.
void onbufferingprogress(unsigned long percent);
onbufferingprogress: function(percent) { console.log("Buffering progress data : " + percent); }
Callback method for asynchronous buffering complete notifications.
void onbufferingcomplete();
onbufferingcomplete: function() { console.log("Buffering complete."); }
Callback method for the current playback time.
void oncurrentplaytime(unsigned long currentTime);
oncurrentplaytime: function(currentTime) { console.log("Current playtime: " + currentTime); }
Callback method for asynchronous playback finished notifications.
void onstreamcompleted();
onstreamcompleted: function() { console.log("Stream Completed"); }
Callback method for asynchronous event notifications.
void onevent(AVPlayEvent eventid, DOMString data);
onevent: function(eventType, eventData) { console.log("OnEvent Callback with eventType: " + eventType); }
Callback method for AVPlay error notifications.
void onerror(AVPlayError eventid);
onerror: function(eventType) { console.log("OnError Event Callback with eventType: " + eventType); }
Callback method for AVPlay detailed error message notifications.
void onerrormsg(AVPlayError eventid, DOMString errorMsg);
Since : 6.0
onerrormsg: function(eventType, errorMsg) { console.log("OnErrorMsg Event Callback with eventType: " + eventType + "Error Message: " + errorMsg); } //errorMsg example: "{"error_code": "PLAYER_ERROR_CONNECTION_FAILED","url": "http://www.xxxxx.m3u8","DownloadSpeed": "10MB/s", // "http_request_header": "xxxxxxxx","http_response_header": "xxxxxxxx", "connect_error": {"curl": -23}}" //errorMsg example: " {"error_code": "PLAYER_ERROR_NOT_SUPPORTED_FORMAT","codec": "h264","demux": "mp4demux", // "resolution": "19201080","fps": "30", "detail_info": "decoder error"}"
Callback method for DRM information notifications.
void ondrmevent(AVPlayDrmType type, drmData data);
ondrmevent: function(drmType, drmData) { console.log("DRM callback, type: " + drmType + ", data: " + drmData); if(drmData.name === 'Challenge') { var ChallengeData = { "NAME": drmData.name, "SESSION_ID": drmData.session_id, "CHALLENGE": drmData.challenge, "CHALLENGE_LEN": drmData.challenge_len, "SERV_URL": drmData.serverurl, "SERV_URL_LEN": drmData.serverurl_len } // Use challenge data to get drm license. } else if (drmData.name === 'DrmError') { var ErrorInfo = { "NAME": drmData.name, "ERROR_CODE": drmData.code, "ERROR_MESSAGE": drmData.message // Generally, it's human readable message. } } }
Callback method for asynchronous subtitle change notifications.
void onsubtitlechange(DOMString duration, DOMString subtitles, DOMString type, AVPlaySubtitleAttribute[] attributes);
onsubtitlechange: function(duration, text, data3, data4) { console.log("Subtitle Changed."); }
This callback interface specifies subscriptions for any notification for sound Analysis.
[Callback=FunctionOnly, NoInterfaceObject] interface AVPlaySoundAnalysisCallback { void ongetexception(WebAPIError err); void onsetexception(WebAPIError err); void ongetbandsarray(long[] band); };
Required for error handling.
void ongetexception(WebAPIError err);
set for error handling.
void onsetexception(WebAPIError err);
Provide the Band Array[32] having sound effect information.
void ongetbandsarray(long[] band);
module AVPlay { enum AVPlayPlayerState { "NONE", "IDLE", "READY", "PLAYING", "PAUSED" }; enum AVPlayDisplayMode { "PLAYER_DISPLAY_MODE_LETTER_BOX", "PLAYER_DISPLAY_MODE_FULL_SCREEN", "PLAYER_DISPLAY_MODE_AUTO_ASPECT_RATIO" }; enum AVPlayBufferOption { "PLAYER_BUFFER_FOR_PLAY", "PLAYER_BUFFER_FOR_RESUME" }; enum AVPlayBufferSizeUnit { "PLAYER_BUFFER_SIZE_IN_SECOND" }; enum AVPlayStreamingPropertyType { "COOKIE", "USER_AGENT", "PREBUFFER_MODE", "ADAPTIVE_INFO", "LISTEN_SPARSE_TRACK", "IS_LIVE", "AVAILABLE_BITRATE", "GET_LIVE_DURATION", "CURRENT_BANDWIDTH", "USE_VIDEOMIXER", "SET_MIXEDFRAME", "PORTRAIT_MODE" }; enum AVPlayDrmType { "PLAYREADY", "VERIMATRIX", "WIDEVINE_CDM" }; enum AVPlayDrmOperation { "SetProperties", "InstallLicense", "ProcessInitiator", "widevine_license_data" }; enum AVPlayStreamType { "VIDEO", "AUDIO", "TEXT" }; enum AVPlayError { "PLAYER_ERROR_NONE", "PLAYER_ERROR_INVALID_PARAMETER", "PLAYER_ERROR_NO_SUCH_FILE", "PLAYER_ERROR_INVALID_OPERATION", "PLAYER_ERROR_SEEK_FAILED", "PLAYER_ERROR_INVALID_STATE", "PLAYER_ERROR_NOT_SUPPORTED_FILE", "PLAYER_ERROR_NOT_SUPPORTED_FORMAT", "PLAYER_ERROR_INVALID_URI", "PLAYER_ERROR_CONNECTION_FAILED", "PLAYER_ERROR_GENEREIC" }; enum AVPlayEvent { "PLAYER_MSG_NONE", "PLAYER_MSG_RESOLUTION_CHANGED", "PLAYER_MSG_BITRATE_CHANGE", "PLAYER_SPARSE_TRACK_DETECT", "PLAYER_STREAMING_EVENT", "PLAYER_MSG_HTTP_ERROR_CODE", "PLAYER_MSG_DRM_CHALLENGE_DATA", "PLAYER_MSG_CUE_TAG_INFO" }; dictionary AVPlayStreamInfo { unsigned long index; AVPlayStreamType type; DOMString extra_info; }; dictionary AVPlaySubtitleAttribute { DOMString attr_type; long start_pos; long stop_pos; }; [NoInterfaceObject] interface AVPlayManagerObject { readonly attribute AVPlayManager avplay; }; WebApi implements AVPlayManagerObject; [NoInterfaceObject] interface AVPlayManager { void open(DOMString url); void close(); void prepare(); void prepareAsync(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback); void setDisplayRect(unsigned long x, unsigned long y, unsigned long width, unsigned long height); void play(); void seekTo(long milliseconds, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback); void stop(); AVPlayPlayerState getState(); void pause(); void jumpForward(long milliseconds, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback); void jumpBackward(long milliseconds, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback); unsigned long getDuration(); unsigned long getCurrentTime(); void setTimeoutForBuffering(unsigned long seconds); void setBufferingParam(AVPlayBufferOption option, AVPlayBufferSizeUnit unit, unsigned long amount); void setSpeed(long playbackSpeed); void setListener(AVPlayPlaybackCallback playbackCallback); DOMString setDrm(AVPlayDrmType drmType, AVPlayDrmOperation drmOperation, DOMString jsonParam); DOMString getUID(AVPlayDrmType drmType); void setSoundAnalysisListener(AVPlaySoundAnalysisCallback soundAnalysisCallback); void unsetSoundAnalysisListener(); void setSilentSubtitle(boolean onoff); void setExternalSubtitlePath(DOMString filePath); void setSubtitlePosition(long position); void setDisplayMethod(AVPlayDisplayMode displayMode); void setSelectTrack(AVPlayStreamType trackType, long trackIndex); AVPlayStreamInfo[] getCurrentStreamInfo(); AVPlayStreamInfo[] getTotalTrackInfo(); void setStreamingProperty(AVPlayStreamingPropertyType propertyType, DOMString propertyParam); DOMString getStreamingProperty(AVPlayStreamingPropertyType propertyType); DOMString getVersion(); void suspend(); void restore(optional DOMString? URL, optional unsigned long? resumeTime, optional boolean? bPrepare); void restoreAsync(optional DOMString? URL, optional unsigned long? resumeTime, optional boolean? bPrepare, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback); }; [Callback=FunctionOnly, NoInterfaceObject] interface AVPlayPlaybackCallback { void onbufferingstart(); void onbufferingprogress(unsigned long percent); void onbufferingcomplete(); void oncurrentplaytime(unsigned long currentTime); void onstreamcompleted(); void onevent(AVPlayEvent eventid, DOMString data); void onerror(AVPlayError eventid); void onerrormsg(AVPlayError eventid, DOMString errorMsg); void ondrmevent(AVPlayDrmType type, drmData data); void onsubtitlechange(DOMString duration, DOMString subtitles, DOMString type, AVPlaySubtitleAttribute[] attributes); }; [Callback=FunctionOnly, NoInterfaceObject] interface AVPlaySoundAnalysisCallback { void ongetexception(WebAPIError err); void onsetexception(WebAPIError err); void ongetbandsarray(long[] band); }; };