Plaintext
// このブロックは公開側には表示されません。
// このブロックを消すとコピーボタンが機能しなくなるので消さないでください。

Customized Object Tag


HDMI Input

BRAVIA Professional Display allows you to embedded HDMI inputs into an application as described below. It is required to set the width attribute and the height attribute.

HTML
<object type="application/x-decimated-video" width="960" height="540"></object>

The last input source (e.g. HDMI 1) is shown in the HDMI Video object tag by default. It can be changed using the INPUT button on a remote commander. It can be changed by using IP Control as well.

BRAVIA Professional Display supports only one HDMI Video object tag in each HTML5 application.

Attributes

  • DOMString autoplay [1]
    autoplay specifies whether to show a blank screen or default external input when an HDMI Video object tag is created.
    • "off" shows a blank screen when an HDMI Video object tag is created. The HTML5 application needs to call open() to show the external input implicitly.
    • "on" shows the last external input when an HDMI Video object tag is created. This value is the default.
  • DOMString src [1]
    Thesrc specifies the URL of the external input. See details below.
Input TypeURI ExampleDescription
HDMIextInput:hdmi?port=1HDMI 1
HDMIextInput:hdmi?port=2HDMI 2
HDMIextInput:hdmi?port=3HDMI 3
HDMIextInput:hdmi?port=4HDMI 4
ComponentextInput:component?port=1Component 1
ComponentextInput:component?port=2Component 2
ComponentextInput:component?port=3Component 3
ComponentextInput:component?port=4Component 4
Wi-Fi DisplayextInput:widi?port=1Wi-Fi Display
CEC RecorderextInput:cec?type=recorder&port=1Recorder 1
CEC RecorderextInput:cec?type=recorder&port=2Recorder 2
CEC RecorderextInput:cec?type=recorder&port=3Recorder 3
CEC PlayerextInput:cec?type=player&port=1Player 1
CEC PlayerextInput:cec?type=player&port=2Player 2
CEC PlayerextInput:cec?type=player&port=3Player 3
CEC TunerextInput:cec?type=tuner&port=1Tuner 1
CEC TunerextInput:cec?type=tuner&port=2Tuner 2
CEC TunerextInput:cec?type=tuner&port=3Tuner 3
Other CEC DeviceextInput:cec?type=freeuseGeneral CEC device

[1] Supported version: WebAppRuntime v1.2.65.11.

Methods

  • void open() [1]
    open() starts showing the external input.
    When autoplay attribute is off, the HDMI Video object tag does not show the external input automatically. The HTML5 application needs to call open() to show the external input explicitly.
  • void close() [1]
    close() stops showing the external input and shows a blank screen.
  • void setWideMode(DOMString mode)
    setWideMode() fills the rectangle with video by stretching. It may be needed when showing a 4:3 video source in the decimated-video. setWideMode() has the following parameters:
    • DOMString mode
      • "16:9" is used to fill a 16:9 rectangle with video.
      • "normal" is used to show a video as-is.

[1] Supported version: WebAppRuntime v1.2.65.11.

Events

  • onInputChanged
    onInputChanged is called when the external input shown in the HDMI Video object tag has been changed. (e.g. This event is called when the external input is changed from HDMI 1 to HDMI 2.)

Example

Download a sample application. The following shows how to embed a decimated HDMI Video object tag to the HTML5 application.

JavaScript
  // Widemode-key detection.
  document.addEventListener( 'keydown', function(e) { if (e.keyCode == VK_PICTURE) { OnPictureKey(); }} );
  
  // Toggle wide mode.
  var cur_wide_mode = 'normal';
  function OnPictureKey() {
  if (cur_wide_mode == 'normal') {
    cur_wide_mode = '16:9';
  } else {
    cur_wide_mode = 'normal';
  }
    document.getElementById('DecimetedVideo').setWideMode(cur_wide_mode);
  }

Multicast Video

BRAVIA Professional Display supports RTP and Raw-UDP multicast video streaming on HTML5 platform with the <object> element. The supported media formats are shown in below.

ContainerVideoAudio-
MPEG TSAVC/HEVC/MPEG2[1]AAC-LC/HE-AAC/MP1L2[1] Multicast object element supports up to 1920x1080@30p framerate and 10Mbps bitrate.

In order for quick stream change and smooth streaming, video streams need to have frequent I-pictures with no B-picture.

Only one <object> element is available at a time. The object cannot be used with the <audio> element or the <video> element at the same time in the same window. Quick creation and deletion of those elements (<object><video> and <audio>) may cause problems due to internal state change and resource management.

The multicast protocol and address is represented in the following format.

multicast-uri = scheme "://" host [":" port]
scheme = "rtp" / "udp"

Methods

  • void show(DOMString url, DOMString jsonParam)
    show() method changes and plays the stream using a passed url.
JSON
object.show('udp://239.0.0.64:5004');

jsonaParam option can handle the following options in JSON format[1].

paramDescription
prebuffer_msThe default duration (ms) that must be buffered for playback to start. Default is 20ms.
rebuffer_msThe default duration (ms) that must be buffered for playback to resume after a rebuffer. Default is 50ms.
hardware_av_syncWhen this flag is set to true, audio and video are synchronized in a hardware decoder and the limit of bitrate and frame rate is improved. However, stability is less than when av are synchronized in the software. The default value is false.
sourceThe parameter can specify the IGMPv3 source address.
allow_render_to_mainIf true, render to main frame. If false, render to sub frame.
drm_key_idWhen this flat is set to “proidiom_stadard”, Pro:Idiom M DRM is enabled.
blocking_modeUsing DRM contents, set this flag to true. The default value is false.
network_interface“eth0”, “ap0”, “wlan0”
JSON
 // set no options
  object.show('udp://239.0.0.64:5004', 0);
  // set options (prebuffer_ms:2000ms, rebuffer_ms:5000ms)
  object.show('udp://239.0.0.64:5004', {prebuffer_ms:2000, rebuffer_ms:4000});

[1] Supported version: WebAppRuntime v1.2.65.8 or later.

  • setWideMode(DOMString mode)
    setWideMode() has the following parameters:
    • DOMString mode
      • "16:9" is used to fill a 16:9 rectangle with video.
      • "normal" is used to show a video as-is.
  • setTextTrack(int)
    The setTextTrack(int) enables DVB subtitle. Set the index to the parameter to select text tracks.
  • DOMString getTextTrackList()
    The getTextTrackList() retrieves the list of available DVB subtitles. The result contains index and language information.
  • setAudioTrack(int)
    The setAudioTrack() can change the audio track. Set index to the parameter to select audio tracks.
  • DOMString getAudioTrackList()
    The getAudioTrackList() retrieves the list of available audio tracks. The result contains index and language information.

Events

  • onstatechange
  • onshow

Example

Please download a sample application that shows how to embed a Multicast Video Window to an application.

At most one multicast video stream can be embedded in a web page. The HTML and JavaScript snippets below show how to use it.

  • HTML
HTML
<object id="mcast" type="application/x-multicast-video" width="960" height="540"></object>
  • JavaScript
JavaScript
// return true on success, or false
function startMulticastPlayback() {
  var object = document.getElementById('mcast');
  
  if (object.open() != 0) {
    return false;
  }
    
  object.onshow = function(result) {
    if (result === 0) {
      console.log('multicast object is opened');
    }
  };
    
  object.onstatechange = function(state) {
    switch (state) {
    case object.STATE_CLOSE:
    case object.STATE_OPEN:
    case object.STATE_PREPARE_TO_PLAY:
    case object.STATE_SRC_CHANGING:
    case object.STATE_WAIT_FOR_DATA:
    case object.STATE_PLAYING:
    case object.STATE_CLOSING:
    default:
      console.log(state);
    }
  };
      
  return object.show('udp://239.0.0.64:5004') === 0;
}
    
// change streams
function changeStream(url) {
  var object = document.getElementById('mcast');
  object.show(url);
    
  // if need to configure buffer size, use below API.
  //   var jsonText = '{"prebuffer_ms":2000,"rebuffer_ms":5000}';
  //   var paramJson = JSON.parse(jsonText);
  //   object.show(url, paramJson);
}
    
// change streams with params
function changeStreamWithParams(url, paramJson) {
  var object = document.getElementById('mcast');
  object.show(url, paramJson);
}

// stop streams
function stopMulticastPlayback() {
  var object = document.getElementById('mcast');
  object.close();
}

High Quality Image

BRAVIA Professional Display provides a special way to render an image file in high-quality in an application. In this case, an image is rendered in a 4K YUV physical plane separated from the RGB plane.

HTML
<object id="hq-img" type="application/x-4k-photo" width="1920" height="1080"></object>

The advantages of this function are:

  • Much better quality compared with <img> tag
  • 4K resolution is supported
  • Preload and cache are supported

However, there are some restrictions:

  • Only one <object> can be opened at a time, and cannot be used with Media Elements (<audio> and <video>) and other <object> elements
  • HTTP cookies are not supported when acquiring the image data
  • Relative path is not supported

Methods

  • long open()
    open() prepares for image rendering and returns 0 on success.
  • void close()
    close() releases the resource for image rendering.
  • long show(DOMString url)
    show() starts loading and rendering the image specified by the parameter "url".
  • long getStatus()
    getStatus() gets the status of the object tag and returns non-zero value when the object tag is opened.
  • long preload(DOMString url)
    preload() preloads the image data specified by the parameter "url" and stores it in the memory.

Events

  • onshow
    onshow is called when the image rendering is complete.
    • 0: success
    • non-zero: error
  • onpreload
    onpreload is called when preload is complete.
    • 0: success or already cached
    • -1: error

Attributes

  • DOMString zoomMode
    zoomMode decides zoom mode
    • values: "NoExpand" or "Smart".
    • default: "NoExpand"
  • boolean is4kPanel
    is4kPanel shows the panel information of the display.
    • true: if the panel is 4k or 8k
    • false: if the panel is not 4k or 8k
  • boolean is4kPlayback
    is4kPlayback shows the capability of the 4k or 8k photo playback mode.
    • true: if the 4k or 8k photo playback mode is enabled in the setting
    • false: if the 4k or 8k photo playback mode is not enabled in the setting

Example

Please download a sample application and it shows a special way to render an image file in high-quality in an application.

The snippet below shows how to preload image data.

JavaScript
var object = document.getElementById('hq-img');
object.open();
object.onpreload = function(url, result) {
  object.show(url);
};
object.preload('https://example.com/4k_image.jpg');

JavaScript API


DirectoryReader Interface

The DirectoryReader interface offers methods concerned with referring information of files and directories under the '/media' directory of a USB storage.

Attributes

  • DOMString result
    result is the result of directory entries in JSON format.

Methods

  • void getTree()
    getTree() method starts directory traversal at the specified path asynchronously. When the operation is finished, the result attribute is updated and the function assigned to onload is called. Or, onerror is called when the operation failed. The result is in JSON format that contains an array of nodes. Symbolic links are not followed.
  • void abort()
    abort() method cancels the request on the object. Then, onabort is called.
  • void readEntries(EntryCallback callback)
    readEntries() method returns directory entries one by one through the callback function. When it reaches the end of the directory entries, the callback function is called with null and onload is called. If the abort() method is called, directory reading is stopped immediately and onabort is called.

Events

  • onload
  • onabort
  • onerror

Example

Define the onload callback and show the result

JavaScript
var reader = new sony.tv.DirectoryReader('/media');
reader.onload = function() {
  var json = JSON.parse(reader.result);
  var jsonStr = JSON.stringify(json, null, '    ');
  console.log(jsonStr);
};
  • Result example If the target directory contains the following, onload is called with the following result in JSON format.
    • Included files:
      • readme.txt (file)
      • LICENSE (file)
      • src (directory with sub entries)
      • main.c (file)
      • plugins (empty directory)
    • Result

JavaScript
[
  {
    "name": "readme.txt",
    "size": 1234,
    "date": "Wed, 28 May 2014 17:00:00 GMT"
  },
  {
    "name": "LICENSE",
    "size": 5678,
    "date": "Wed, 28 May 2014 17:00:00 GMT"
  },
  {
    "name": "src",
    "date": "Wed, 28 May 2014 17:00:00 GMT",
    "children": [
      {
        "name": "main.c",
        "size": 321,
        "date": "Wed, 28 May 2014 17:00:00 GMT"
      }
      {
        "name": "plugins",
        "date": "Wed, 28 May 2014 17:00:00 GMT",
        "children": [],
        "items": []
      }
    ]
  }
]

SystemEvents Interface

An application can receive notifications of system events by the SystemEvents interface.
The below table shows supported event types.

Event typeDescriptionSystemEventsTypeIdSystemEventInfo
Power StatusInform when the status of power is changed.
(i.e. display is turned on or turned off.)
powerStatusChangedPowerStatusInfo
Network InterfaceInform when the status of network interface (eth/wlan) is changed.
(i.e. network interface is disabled or enabled.)
networkInterfaceChangedNetworkInterfaceInfo
Network ConnectionInform when the status of network connection (eth/wlan) is changed.
(i.e. network connection is established or disconnected.)
networkStatusChangedNetworkStatusInfo
External Input StatusInform when the status of external input (HDMI only) is changed.
(i.e. external input is connected or disconnected with the other device or input signal is detected or lost.)
inputsStatusChangedInputsStatusInfo
Volume StatusInform when the volume or mute status is changed.volumeInfoChangedVolumeInfo
Request of Input Source Change[1]Notify when the change of the input source is requested.beforeInputSrcChangeInputSrcInfo
Completion of Input Source Change[1]Notify when the change of the external input is completed.inputSrcChangedInputSrcInfo

[1] Supported only on WebAppRuntime v1.2.65.11.

The SystemEvents interface offers methods to inform the changes of system events (shown in the above table) to an application. An application can control their status by receiving system event status. (i.e. An application can add the decimated object tag only when external input event has been detected.)

Interface: SystemEvents

Methods

  • void addListener(SystemEventsTypeId type, SystemEventsCallback callback)
  • void removeListener(SystemEventsTypeId type, SystemEventsCallback callback)

Interface: SystemEvent

SystemEvent is the event of SystemEventsCallback.

Attributes

  • SystemEventsTypeId systemEventTypeId
  • SystemEventInfo eventMessage

Methods

  • void preventDefault()
    When the HTML5 application calls preventDefault(), the propagation of the event is stopped. Its default action should not be taken as it normally would be. The HTML5 application should handle its default action explicitly.
    This method is available in InputSrcInfo.

Enum: SystemEventsTypeId

It represents the system event types.

  • powerStatusChanged
    Inform RC ON and RC OFF
  • networkInterfaceChanged
    Inform network interface (eth/wlan) is enabled or disabled
  • networkStatusChanged
    Inform network connection is established, IP status is changed
  • inputsStatusChanged
    Inform external input status is changed (support only HDMI)
  • volumeInfoChanged
    Inform volume and mute status is changed
  • beforeInputSrcChange
    Notify when the change of the input source is requested.
  • inputSrcChanged
    Notify when the change of the external input is completed.

Interface: SystemEventInfo

SystemEventInfo is the base interface of each event status.

Attributes

  • DOMTimeStamp timeStamp
    timestamp shows the time when the event has been fired.

Interface: PowerStatusInfo

PowerStatusInfo inherits SystemEventInfo and represents the power information.

Attributes

  • PowerStatusType status

Enum: PowerStatusType

It represents the RC ON and OFF event types.

  • active
    This value represents RC ON
  • standby
    This value represents RC OFF

Interface: NetworkInterfaceInfo

NetworkInterfaceInfo inherits SystemEventInfo and represents the network interface (wlan and wired) information.

Attributes

  • NetworkInterfaceType netif
    This attribute shows the network interface which is enabled or disabled
  • boolean enabled

enabled shows the network interface is enabled or disabled.

  • true if network interface is enabled.
  • false if network interface is disabled.

Enum: NetworkInterfaceType

NetworkInterfaceType represents network interface type.

  • wlan0
  • eth0

Interface: NetworkStatusInfo

NetworkStatusInfo inherits SystemEventInfo and represents the network connection status (wlan and wired).

Attributes

  • NetworkConnectionStatus connectionInfo
    connectionInfo shows the network connection information (IP address, netmask and so on).
  • boolean enabled
    enabled shows the network connection is established or not.
    • true if network is established
    • false if network is disconnected

Interface: NetworkConnectionStatus

NetworkConnectionStatus represents the network connection detail status.

Attributes

  • NetworkInterfaceType netif
  • DOMString errorDetail
  • DOMString hwAddress
  • DOMString ipAddrV4
  • DOMString ipAddrV6
  • DOMString netmask
  • DOMString gateway
  • Array dns

Interface: InputsStatusInfo

InputsStatusInfo inherits SystemEventInfo and represents the external input (HDMI) status.

Attributes

  • DOMString uri
    uri shows external input which changes status.
  • DOMString title
    title shows the name of external input (e.g. HDMI 1, HDMI 2, ...)
  • boolean connection
    connection shows HDMI device connection status.
    • true if HDMI device is connected.
    • false if HDMI device is disconnected
  • boolean status
    status shows HDMI signal status.
    • true if HDMI input signal is detected.
    • false if HDMI input signal is lost.

Interface: VolumeInfo

VolumeInfo inherits SystemEventInfo and represents the volume status.

Attributes

  • Numeric volume
    volume shows volume value.
  • boolean mute
    mute shows volume is muted or not.
    • true if volume turn to muted.
    • false if mute is canceled.

Interface: InputSrcInfo

InputSrcInfo inherits SystemEventInfo and represents the information related to beforeInputSrcChange and inputSrcChanged .

Attributes

  • DOMString uri
    uri shows the URL of the external input.
  • DOMString title
    title shows the external input name (e.g. HDMI 1, HDMI 2, ...)
  • DOMString dispNum
    dispNum shows the sequence number of the external input (e.g. “HDMI 1”: “1”)

Example

Define and register callbacks

JavaScript
// define callback to handle Power Status events
function onPowerStatusChanged(event){
  console.log("systemEventTypeId = " + event.systemEventTypeId);
  console.log("eventMessage.timestamp = " + event.eventMessage.timeStamp);
  console.log("eventMessage.status = " + event.eventMessage.status);
}
// define callback to handle Network Interface events
function onNetworkInterfaceChanged(event){
  console.log("systemEventTypeId = " + event.systemEventTypeId);
  console.log("eventMessage.timestamp = " + event.eventMessage.timeStamp);
  console.log("eventMessage.netif = " + event.eventMessage.netif);
  console.log("eventMessage.enabled = " + event.eventMessage.enabled);
}
// define callback to handle Network Status events
function onNetworkStatusChanged(event){
  console.log("systemEventTypeId = " + event.systemEventTypeId);
  console.log("eventMessage.timestamp = " + event.eventMessage.timeStamp);
  console.log("eventMessage.connectionInfo.netif = " + event.eventMessage.connectionInfo.netif);
  console.log("eventMessage.connectionInfo.errorDetail = " + event.eventMessage.connectionInfo.errorDetail);
  console.log("eventMessage.connectionInfo.hwAddress = " + event.eventMessage.connectionInfo.hwAddress);
  console.log("eventMessage.connectionInfo.ipAddrV4 = " + event.eventMessage.connectionInfo.ipAddrV4);
  console.log("eventMessage.connectionInfo.ipAddrV6 = " + event.eventMessage.connectionInfo.ipAddrV6);
  console.log("eventMessage.connectionInfo.netmask = " + event.eventMessage.connectionInfo.netmask);
  console.log("eventMessage.connectionInfo.gateway = " + event.eventMessage.connectionInfo.gateway);
  console.log("eventMessage.connectionInfo.dns = " + event.eventMessage.connectionInfo.dns);
  console.log("eventMessage.enabled = " + event.eventMessage.enabled);
}
// define callback to handle External Input Status events
function onInputsStatusChanged(event){
  console.log("systemEventTypeId = " + event.systemEventTypeId);
  console.log("eventMessage.timestamp = " + event.eventMessage.timeStamp);
  console.log("eventMessage.uri = " + event.eventMessage.uri);
  console.log("eventMessage.title = " + event.eventMessage.title);
  console.log("eventMessage.connection = " + event.eventMessage.connection);
  console.log("eventMessage.status = " + event.eventMessage.status);
}
// define callback to handle Volume Status events
function onVolumeInfoChanged(event){
  console.log("systemEventTypeId = " + event.systemEventTypeId);
  console.log("eventMessage.timestamp = " + event.eventMessage.timeStamp);
  console.log("eventMessage.volume = " + event.eventMessage.volume);
  console.log("eventMessage.mute = " + event.eventMessage.mute);
}

// define callback to handle request of Input Source Change
function onBeforeInputSrcChange(event){
  console.log("systemEventTypeId = " + event.systemEventTypeId);
  console.log("eventMessage.url = " + event.eventMessage.url);
  console.log("eventMessage.title = " + event.eventMessage.title);
  console.log("eventMessage.dispNum = " + event.eventMessage.dispNum);
}

// define callback to handle completion of Input Source Change
function onInputSrcChanged(event){
  console.log("systemEventTypeId = " + event.systemEventTypeId);
  console.log("eventMessage.url = " + event.eventMessage.url);
  console.log("eventMessage.title = " + event.eventMessage.title);
  console.log("eventMessage.dispNum = " + event.eventMessage.dispNum);
}

// register callbacks
sony.tv.systemevents.addListener('powerStatusChanged', onPowerStatusChanged);
sony.tv.systemevents.addListener('networkInterfaceChanged', onNetworkInterfaceChanged);
sony.tv.systemevents.addListener('networkStatusChanged', onNetworkStatusChanged);
sony.tv.systemevents.addListener('inputsStatusChanged', onInputsStatusChanged);
sony.tv.systemevents.addListener('volumeInfoChanged', onVolumeInfoChanged);
sony.tv.systemevents.addListener('beforeInputSrcChange', onBeforeInputSrcChange);
sony.tv.systemevents.addListener('inputSrcChanged', onInputSrcChanged);

// unregister callbacks
sony.tv.systemevents.removeListener('powerStatusChanged', onPowerStatusChanged);
sony.tv.systemevents.removeListener('networkInterfaceChanged', onNetworkInterfaceChanged);
sony.tv.systemevents.removeListener('networkStatusChanged', onNetworkStatusChanged);
sony.tv.systemevents.removeListener('inputsStatusChanged', onInputsStatusChanged);
sony.tv.systemevents.removeListener('volumeInfoChanged', onVolumeInfoChanged);
sony.tv.systemevents.removeListener('beforeInputSrcChange', onBeforeInputSrcChange);
sony.tv.systemevents.removeListener('inputSrcChanged', onInputSrcChanged);

PictureMode Interface

The PictureMode interface offers methods to set and fix to a particular mode.
By fixing the picture mode to a particular mode, an application can avoid a blinking screen even if the contents on it are changed.

Picture mode can be fixed in the manifest ("fixed_input: true"). In this case, the picture mode setting in the manifest is prioritized and this JavaScript API is ignored.

Methods Interface

  • DOMString getPictureMode()
    getPictureMode() method gets current picture mode.
  • void setPictureMode(DOMString mode)
    setPictureMode() method changes and fixes the picture mode. The mode parameter is one of three strings: 'VIDEO''PHOTO' and 'AUTO'. If the picture mode is set to other than 'AUTO', the picture mode is fixed until it is set to 'AUTO'.

Example

  • Set Picture Mode
JavaScript
  function setPictureModeCall(mode) {
    sony.tv.picturemode.setPictureMode(mode);
  }

  // Set picture mode as 'VIDEO'
  setPictureModeCall('VIDEO');
  // Set picture mode as 'PHOTO'
  setPictureModeCall('PHOTO');
  // Set picture mode as 'AUTO'
  setPictureModeCall('AUTO');