<script type="text/javascript" src="$WEBAPIS/avplayextension/avplayextension.js"></script>
should be loaded in "index.html".
The module defines the functionalities of the player that are exposed and which could be easily used by an application or widget developer to support multimedia (RTP/UDP) playback for audio or video that are provided by the Tizen Samsung Product API.
Since : 6.5
Product : B2B (HTV, LFD)
This enumeration defines the player states.
enum AVPlayPlayerState { "NONE", "IDLE", "READY", "PLAYING", "PAUSED" };
The following values are supported
This enumeration defines the possible values for webapis.avplay.setDisplayMethod()
enum AVPlayDisplayMode { "PLAYER_DISPLAY_MODE_LETTER_BOX", "PLAYER_DISPLAY_MODE_FULL_SCREEN", "PLAYER_DISPLAY_MODE_AUTO_ASPECT_RATIO" };
This enumeration specifies the values for a specific feature in UDP/RTP.
enum AVPlayStreamingPropertyType { "ENABLE_TTX", "SET_INTERACTIVE_MODE" };
This enumeration specifies the different DRM types defined by the player.
enum AVPlayDrmType { "PROIDIOM", "LYNK" };
This enumeration defines the different DRM operations by the player.
enum AVPlayDrmOperation { "Initialize", "Finalize" };
This enumeration defines the Stream types defined by the player.
enum AVPlayStreamType { "VIDEO", "AUDIO", "TEXT" };
The AVPlayStreamInfo dictionary specifies the streaming media-related information for the video, audio, and the subtitles during various streaming scenarios.
dictionary AVPlayStreamInfo { unsigned long index; AVPlayStreamType type; DOMString extra_info; };
The DRMData dictionary specifies information about the data received from the player via the DRM event.
dictionary DRMData { DOMString name; long code; DOMString message; long reserved; };
The interface defines what is instantiated by the WebApi object of the Tizen-based Samsung TV Product API. There will be a webapis object that allows access to the functionality of the AVPlay API.
[NoInterfaceObject] interface AVPlayManagerObject { readonly attribute AVPlayManager avplay; };
WebApi implements AVPlayManagerObject;
This interface provides methods to use 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 stop(); AVPlayPlayerState getState(); unsigned long getCurrentTime(); void setListener(AVPlayPlaybackCallback playbackCallback); DOMString setDrm(AVPlayDrmType drmType, AVPlayDrmOperation drmOperation, DOMString jsonParam); void setDisplayMethod(AVPlayDisplayMode displayMode); void setSelectTrack(AVPlayStreamType trackType, long trackIndex); AVPlayStreamInfo getCurrentStreamInfo(); AVPlayStreamInfo[] getTotalTrackInfo(); void setStreamingProperty(AVPlayStreamingPropertyType propertyType, Any propparam); DOMString getVersion(); void setDisplayRotation(DOMString displayRotation); };
This method instantiates the player object and takes the content URL as the input parameter.
void open(DOMString url);
Constraint :
Privilege Level : Partner
Privilege : http://developer.samsung.com/privilege/streamingtvplayer
Parameters :
Exceptions :
Code Example :
try { webapis.avplay.open(url); } catch (e) { console.log(e); }
This method destroys the AVPlay object.
void close();
try { webapis.avplay.close(); } catch (e) { console.log(e); }
This method prepares the media player for playback. The Player must have been created beforehand with a valid URI. This prepare method is synchronous. Hence, the calling context would be blocked until the player is prepared.
void prepare();
try { webapis.avplay.prepare(); } catch (e) { console.log(e); }
This method prepares the media player for playback, asynchronously. This API prepares the MM core module, asynchronously. It means that the internal media elements will change the state, asynchronously. We recommend this asynchronous prepareAsync call instead of the prepare call which is synchronous API which blocks the entire application during its execution. prepareAsync() returns immediately, rather than blocking until enough data has been buffered. Since this works in asynchronous model, this does not block the executing thread and the application is responsive during its execution. When prepareAsync() gets successfully completed, it returns with successCallback and player reached in READY state. For some reason, e.g. network error, it returns with errorCallback with error value.
void prepareAsync(optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
webapis.avplay.prepareAsync(successCallback, errorCallback);
This method sets the display area for playing the video content on the TV screen. It should be called for showing the video after calling an open method. App's default resolution is 1920x1080. It needs 4 parameters (left,top,width,height) that always use 1920 x 1080 coordinate system regardless of your 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); }
This method starts the playback of the stream.
void play();
try { webapis.avplay.play(); } catch (e) { console.log(e); }
This method stops the player and hence any video that is currently being played.
void stop();
try { webapis.avplay.stop(); } catch (e) { console.log(e); }
This method returns the current state of the underlying player which is associated with the AVPlay object.
AVPlayPlayerState getState();
Return Value :
var bRet = webapis.avplay.getState();
This method returns the current play time in milliseconds.
unsigned long getCurrentTime();
var currentPlayTime = webapis.avplay.getCurrentTime();
This method is used in order to obtain the Player information, the DRM mode information etc., and the Callback function is registered. When the relevant Event occurs, the relevant Callback function gets called asynchronously.
void setListener(AVPlayPlaybackCallback playbackCallback);
var listener = { onevent: function(eventType, eventData) { console.log("event type error : " + eventType + ", data: " + eventData); }, onerror: function(eventType) { console.log("event type error : " + eventType); }, ondrmevent: function(drmEvent, DRMData) { console.log("DRM callback: " + drmEvent + ", data: " + DRMData); } } webapis.avplay.setListener(listener);
This method updates the DRM information, such as SetProperties, etc. It changes the DRM mode, and runs the Control feature. Every DRM has difference between AVPlayDrmOperation and jsonParam.
DOMString setDrm(AVPlayDrmType drmType, AVPlayDrmOperation drmOperation, DOMString jsonParam);
Privilege Level : Public
Privilege : http://developer.samsung.com/privilege/drmplay
NOTE : if you use this API, a special privilege level is required. Insert the http://developer.samsung.com/privilege/drmplay in the config.xml file of the web application. Check below example <tizen:privilege name="http://developer.samsung.com/privilege/drmplay"/>
(Example) ProIdiom (setting forensic data) var drmParam = new Object(); drmParam.ForensicData = "XXXXXXX"; playerObj.setDrm("PROIDIOM", "Initialize", JSON.stringify(drmParam)); (Example) LYNKDRM (setting type and lynk server) var drmParam = new Object(); drmParam.type ="2"; drmParam.LYNKServer="xxx.xxx.xxx.xxx:xxxxx"; playerObj.setDrm( "LYNK", "Initialize", JSON.stringify(drmParam));
This method sets the Video Screen Mode within the given DISPLAY area.
void setDisplayMethod(AVPlayDisplayMode displayMode);
webapis.avplay.setDisplayMethod("PLAYER_DISPLAY_MODE_FULL_SCREEN");
This method is used with Multi Audio/Subtitle, when you want to change the Audio and Subtitle while playing.
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); } } //For example, choose the subtitle track index number 2. webapis.avplay.setSelectTrack('TEXT',2);
This method gets the currently playing Streams Video, Audio, and Subtitle information. It informs 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 of stream type has extra_info which is JsonString. video extra_info example : "{fourCC:"H264","Width":"1920","Height":"1080","Bit_rate":" 477000"}" audio extra_info example : "{"language":"fr","channels":"2","sample_rate":"48000","bit_rate":"256000","fourCC":"mpeg","track_lang":"fra","audio_type":"0"}" text(subtitle) extra_info example : "{"track_lang":"eng","subtitle_type":"0","pid":"258","subtitle_mode":"0"}" In the case of invalid Stream, the DOMString becomes null and the index value becomes -1.
This method gets the currently playing Streams 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 + ''; }
This method sets the value for a specific feature in the UDP/RTP playback.
void setStreamingProperty(AVPlayStreamingPropertyType propertyType, Any propparam);
set interactive mode example : var propparam = new Object(); propparam.mode ="1"; propparam.latency="100"; //latency in ms webapis.avplay.setStreamingProperty("SET_INTERACTIVE_MODE", propparam); Enable ttx mode example : webapis.avplay.setStreamingProperty("ENABLE_TTX", true);
This method gets the version of avplay.
DOMString getVersion();
var version = webapis.avplay.getVersion();
This method sets the rotation settings of the video surface display. If no display is set, no operation is performed. Use this method to change the video orientation to portrait mode. This API call will change the origin of the coordinates. Hence, the application should call setDisplayRect() again after calling this API.
void setDisplayRotation(DOMString displayRotation);
webapis.avplay.setDisplayRotation("PLAYER_DISPLAY_ROTATION_90");
module AVPlayExtension { 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 AVPlayStreamingPropertyType { "ENABLE_TTX", "SET_INTERACTIVE_MODE" }; enum AVPlayDrmType { "PROIDIOM", "LYNK" }; enum AVPlayDrmOperation { "Initialize", "Finalize" }; enum AVPlayStreamType { "VIDEO", "AUDIO", "TEXT" }; dictionary AVPlayStreamInfo { unsigned long index; AVPlayStreamType type; DOMString extra_info; }; dictionary DRMData { DOMString name; long code; DOMString message; long reserved; }; [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 stop(); AVPlayPlayerState getState(); unsigned long getCurrentTime(); void setListener(AVPlayPlaybackCallback playbackCallback); DOMString setDrm(AVPlayDrmType drmType, AVPlayDrmOperation drmOperation, DOMString jsonParam); void setDisplayMethod(AVPlayDisplayMode displayMode); void setSelectTrack(AVPlayStreamType trackType, long trackIndex); AVPlayStreamInfo getCurrentStreamInfo(); AVPlayStreamInfo[] getTotalTrackInfo(); void setStreamingProperty(AVPlayStreamingPropertyType propertyType, Any propparam); DOMString getVersion(); void setDisplayRotation(DOMString displayRotation); }; };