Skip to content

Instantly share code, notes, and snippets.

@aabytt
Last active April 29, 2024 11:14
Show Gist options
  • Save aabytt/bddbb1bcf031a050d89a89aeee3a6737 to your computer and use it in GitHub Desktop.
Save aabytt/bddbb1bcf031a050d89a89aeee3a6737 to your computer and use it in GitHub Desktop.
more useful stuff on lg webos

Playling a link with standard LG webOS player

  • id - id of the player app, com.webos.app.mediadiscovery for webOS 6+, com.webos.app.photovideo for webOS 3.x-5.x, com.webos.app.smartshare for webOS 1.0-2.x
  • fullPath - url of the video file
  • fileName - name of the video displayed in player. Filename is remembered by the player to continue playback from exit timestamp

from a web app

webOS.service.request("luna://com.webos.applicationManager", {
           method: "launch",
           parameters: { "id": "com.webos.app.photovideo", "params": {"payload":[{
		"fullPath":"https://media.w3.org/2010/05/sintel/trailer.mp4",
		"artist":"",
		"subtitle":"",
		"dlnaInfo":{"flagVal":4096,"cleartextSize":"-1","contentLength":"-1","opVal":1,"protocolInfo":"http-get:*:video/x-matroska:DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=01700000000000000000000000000000","duration":0},
		"mediaType":"VIDEO",
		"thumbnail":"",
		"deviceType":"DMR",
		"album":"",
		"fileName":"trailer",
		"lastPlayPosition":-1}]}},
           onSuccess: function (inResponse) {
               console.log("The app is launched");
           },
           onFailure: function (inError) {
               console.log("Failed to launch the app");
               console.log("[" + inError.errorCode + "]: " + inError.errorText);
               return;
           }
       });

from shell

luna-send-pub -n 1 -f luna://com.webos.applicationManager/launch '{"id": "com.webos.app.photovideo", "params": {"payload":[{"fullPath":"https://media.w3.org/2010/05/sintel/trailer.mp4","artist":"","subtitle":"","dlnaInfo":{"flagVal":4096,"cleartextSize":"-1","contentLength":"-1","opVal":1,"protocolInfo":"http-get:*:video/x-matroska:DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=01700000000000000000000000000000","duration":0},"mediaType":"VIDEO","thumbnail":"","deviceType":"DMR","album":"","fileName":"trailer","lastPlayPosition":-1}]}}'

Turning screen backlight off (root)

# 1
luna-send -f -n 1 luna://com.webos.service.settings/setSystemSettings '{"category":"picture","settings":{"energySaving":"screen_off","energySavingModified":"true"}}'
//screen will turn back on with any remote key

# 2
luna-send -n 1 "luna://com.webos.service.tvpower/power/turnOffScreen" '{}'
luna-send -n 1 "luna://com.webos.service.tvpower/power/turnOnScreen" '{}'

Making screenshot with timestamp filename

luna-send -n 1 -f 'luna://com.webos.service.capture/executeOneShot' '{"path":"/tmp/'"$(date +%Y_%m_%d_%H-%M-%S)"'_capture.png","method":"DISPLAY","format":"PNG"}'

Getting mediaId

mediaId is assigned by webos media server to any opened media pipeline. Value is required to perform direct com.webos.media calls to control playback of videos.

Read from web app

document.querySelector('video').mediaId

Public Luna calls that return video details including mediaId (may not be supported on older webOS versions)

luna://com.webos.service.videooutput/getStatus luna://com.webos.media/getForegroundAppInfo

Private Luna call

luna://com.webos.media/getActivePipelines

Undocumented com.webos.media calls

Direct use of com.webos.media by application developers is strongly discouraged. Instead, the media interfaces native to a particular application framework (e.g. Web, QT, SDL/NDL) should be used. However some standard web apis (like managing subtitles) are not supported leaving us no choice rather to use direct calls.

Subtitles show/hide

method setSubtitleEnable parameters:

  • mediaId
  • enable - true to show subtitles, false to hide subtitles

Example

webOS.service.request("luna://com.webos.media", {
	    method:"setSubtitleEnable",
	    parameters: { 
			"mediaId": "_MQUBT01X5MiTj4",
			"enable": true
			},
	      onSuccess: function (result) {
                 console.log(JSON.stringify(result));
		}
	      },
	      onFailure: function (result) {
	        console.log( "[fail][" + result.errorCode + "] " + result.errorText );
	        }
	 });

Select subtitle and audiotracks

method selectTrack parameters:

  • mediaId
  • type - audio for audiotracks, text for subtitletracks
  • index - number of track (0...n)

Subtitle size

method setSubtitleFontSize parameters:

  • mediaId
  • fontSize - values: 0 for tiny, 1 - small, 2 - standard (default), 3 - large, 4 - huge

Subtitle color

method setSubtitleColor parameters:

  • mediaId
  • color - values: 0 - yellow, 1 - red, 2 - white (default), 3 - green, 4 - blue, 5 - gray

Subtitle position

method setSubtitlePosition parameters:

  • mediaId
  • position - values: -3for lowest position, -2, -1,0 (default), 1, 2, 3, 4 for highest position

Subtitle opacity

method setSubtitleCharacterOpacity parameters:

  • mediaId
  • charOpacity - values: from 0 for fully transparent to 255 for non-transparent (default)

Subtitle character color

(seems to do the same as setSubtitleColor but some different values) method setSubtitleCharacterColor parameters:

  • mediaId
  • charColor - values: black, white (default), yellow, red, green, blue

Subtitle background opacity

method setSubtitleBackgroundOpacity parameters:

  • mediaId
  • bgOpacity - values: from 0 for fully transparent (default) to 255 for non-transparent

Subtitle background color

method setSubtitleBackgroundColor parameters:

  • mediaId
  • bgColor - values: black (default), white, yellow, red, green, blue

Subtitle window opacity

method setSubtitleWindowOpacity parameters:

  • mediaId
  • windowOpacity - values: from 0 for fully transparent (default) to 255 for non-transparent

Subtitle window color

method setSubtitleWindowColor parameters:

  • mediaId
  • windowColor - values: black (default), white, yellow, red, green, blue

Subtitle encoding

method setSubtitleEncoding parameters:

  • mediaId
  • encoding - values: ISO8859-1, ISO6937, UTF-8, WINDOWS-1252, WINDOWS-1250, ISO8859-4, WINDOWS-1251, WINDOWS-1256, WINDOWS-1253, ISO8859-8, ISO8859-9, ISO8859-11, WINDOWS-1258, BIG5, GB2312, EUCKR, Shift_JIS

External subtitles

method setSubtitleSource parameters:

  • mediaId
  • uri link to subtitles file (i.e. http://some.website/filename.srt or local file file:///tmp/usb/sda/sda1/filename.srt)
  • preferredEncodings - optional parameter

Subtitles sync

method setSubtitleSync parameters:

  • mediaId
  • sync - values: +-sync in milliseconds (i.e. -350, 200, 1500, etc)

Playback speed

method setPlayRate parameters:

  • mediaId
  • playRate - values from 0.1 to 2.0, default is 1.0
  • audioOutput - true, audio is played only up to x2 playback rate

Subscribe to events

To get video detailed data like number of embedded audio and subtitle tracks may be needed to subscribe to pipeline events and parse sourceInfo generated after media is loaded (https://www.webosose.org/docs/reference/ls2-api/com-webos-media/#sourceinfo-1)

method subscribe parameters:

  • mediaId
  • subscribe - true

To unsubscribe use method unsubscribe with only parameter mediaId

Example of sourceInfo object

{"sourceInfo":{"numPrograms":1,"container":"mkv","seekable":true,"trickable":true,"programInfo":[{"duration":1295552,"numAudioTracks":4,"audioTrackInfo":[{"bitRate":0,"language":"ru","codec":"ac3","sampleRate":48,"channels":2,"audioType":0},{"bitRate":0,"language":"ru","codec":"ac3","sampleRate":48,"channels":2,"audioType":0},{"bitRate":0,"language":"ru","codec":"ac3","sampleRate":48,"channels":2,"audioType":0},{"bitRate":0,"language":"en","codec":"ac3","sampleRate":48,"channels":6,"audioType":0} ],"numVideoTracks":1,"videoTrackInfo":[{"angleNumber":0,"level":3.1,"width":1280,"height":720,"codec":"H264","profile":"high","frameRate":23.976,"progressive":true} ],"numSubtitleTracks":2,"subtitleTrackInfo":[{"language":"ru","type":"text"},{"language":"en","type":"text"} ]} ],"mediaId":"_MQUBT01X5MiTj4"}}

Tracks order

Audiotrack may have disposition.default tag. WebOS 4+ reads this tag and puts the track marked as default into the first position of tracks list (index 0)

@stiw47
Copy link

stiw47 commented Jan 17, 2024

What if forcing alert close with a luna call? Will it revert back to TV speaker as well?

I already tried exactly that one from your link and no joy. Yes, it will revert back to TV speaker when alert is closed. It seems that I have to confirm alert somehow, either if find API call to confirm or with sending ENTER button event.

This is some workflow:

  1. Sending call to connect - BT is connected, but alert appear and asking to switch to BT sound output:
    root@LGwebOSTV:~# luna-send -f -n 1 luna://com.webos.service.bluetooth2/a2dp/connect '{"address": "7b:b1:b9:be:82:fe"}'
    image

  2. Sending call to change sound output - sound output has been changed, but alert stay:
    root@LGwebOSTV:~# luna-send -f -n 1 luna://com.webos.service.apiadapter/audio/changeSoundOutput '{"output": "bt_soundbar"}'
    image

  3. Sending call to dismiss all alerts - alert has been dismissed, but sound output has been reverted back to TV speaker as well:
    root@LGwebOSTV:~# luna-send -n 1 -f -a com.webos.service.battest luna://com.webos.notification/closeAllAlerts '{}'
    image

@aabytt
Copy link
Author

aabytt commented Jan 17, 2024

Run ls-monitor and check in logs what is happening when you hit Yes button with a remote.

@stiw47
Copy link

stiw47 commented Jan 17, 2024

Great point, didn't know for ls-monitor, great.
Huh, since you recommended ls-monitor, you are probably know that logs pumps insanely fast (cause it is probably logging everything what happens on TV).

Anyway, playing fast fingers, this is something what I caught with stop it with Ctrl+C as soon as I hit ENTER button on remote:

nt":1}»
312.173 RX return       1722            com.lge.settingsservice (sYicqN1r)              com.webos.service.db (l0IbSe2C) «{"returnValue":true,"count":1}»
312.174 TX  call        1723            com.lge.settingsservice (sYicqN1r)              com.webos.service.db (l0IbSe2C)         /com/palm/luna/private/cancel    «{"token":1722}»
312.174 TX  return      839             com.lge.settingsservice (sYicqN1r)              com.webos.service.audio (hBjngH5b)      «{"method":"setSystemSettingDesc","returnValue":true}»
312.174 RX return       839             com.webos.service.audio (hBjngH5b)              com.webos.settingsservice (sYicqN1r)    «{"method":"setSystemSettingDesc","returnValue":true}»
312.174 TX  call        1725            com.lge.settingsservice (sYicqN1r)      com.webos.service.db (l0IbSe2C)         (null)          //merge  «{"query":{"from":"com.webos.settings.desc.system:1","where":[{"op":"=","prop":"key","val":"userEqualizer"},{"op":"=","prop":"app_id","val":""}]},"props":{"dbtype":"G","ui":{"active":false},"category":"sound","key":"userEqualizer"}}»
312.175 RX call 1723            com.palm.db (l0IbSe2C)          com.lge.settingsservice (sYicqN1r)              /com/palm/luna/private/cancel    «{"token":1722}»
312.175 RX call 1725            com.palm.db (l0IbSe2C)  com.lge.settingsservice (sYicqN1r)              (null)          //merge «{"query":{"from":"com.webos.settings.desc.system:1","where":[{"op":"=","prop":"key","val":"userEqualizer"},{"op":"=","prop":"app_id","val":""}]},"props":{"dbtype":"G","ui":{"active":false},"category":"sound","key":"userEqualizer"}}»
312.180 TX  return      1725            com.palm.db (l0IbSe2C)          com.lge.settingsservice (sYicqN1r)      «{"returnValue":true,"count":1}»
312.180 RX return       1725            com.lge.settingsservice (sYicqN1r)              com.webos.service.db (l0IbSe2C) «{"returnValue":true,"count":1}»
312.182 TX  call        1726            com.lge.settingsservice (sYicqN1r)              com.webos.service.db (l0IbSe2C)         /com/palm/luna/private/cancel    «{"token":1725}»
312.182 TX  return      840             com.lge.settingsservice (sYicqN1r)              com.webos.service.audio (hBjngH5b)      «{"method":"setSystemSettingDesc","returnValue":true}»
312.182 RX call 1726            com.palm.db (l0IbSe2C)          com.lge.settingsservice (sYicqN1r)              /com/palm/luna/private/cancel    «{"token":1725}»
312.182 RX return       840             com.webos.service.audio (hBjngH5b)              com.webos.settingsservice (sYicqN1r)    «{"method":"setSystemSettingDesc","returnValue":true}»
312.236 TX  call        232             com.webos.service.btaudiosrc (H4Ma5luW) com.webos.service.bluetooth2 (LpVH8he9)         (null)  /a2dp/internal/setSbcEncoderBitpool      «{"address":"7b:b1:b9:be:82:fe","bitpool":30}»
312.236 RX call 232             com.webos.service.bluetooth2 (LpVH8he9) com.webos.service.btaudiosrc (H4Ma5luW)         (null)          /a2dp/internal/setSbcEncoderBitpool      «{"address":"7b:b1:b9:be:82:fe","bitpool":30}»
312.237 TX  return      232             com.webos.service.bluetooth2 (LpVH8he9)         com.webos.service.btaudiosrc (H4Ma5luW) «{"adapterAddress":"20:28:bc:1f:de:dd","address":"7b:b1:b9:be:82:fe","returnValue":true}»
312.238 RX return       232             com.webos.service.btaudiosrc (H4Ma5luW)         com.webos.service.bluetooth2 (LpVH8he9) «{"adapterAddress":"20:28:bc:1f:de:dd","address":"7b:b1:b9:be:82:fe","returnValue":true}»
312.239 TX  call        233             com.webos.service.btaudiosrc (H4Ma5luW)         com.webos.service.bluetooth2 (LpVH8he9)         /com/palm/luna/private/cancel    «{"token":232}»
312.239 RX call 233             com.webos.service.bluetooth2 (LpVH8he9)         com.webos.service.btaudiosrc (H4Ma5luW)         /com/palm/luna/private/cancel    «{"token":232}»

So, bluetooth connection was already initiated, BT device connected. Then I remember the last line in ls-monitor, then hit the ENTER on remote to confirm the alert, and stopped monitor with Ctrl+C as soon as alert was confirmed.

As for now, I don't get it, but will play more with this later tonight, now I am still busy on job 😁.

Thank you for the great hint, it could be something from this point.

@aabytt
Copy link
Author

aabytt commented Jan 17, 2024

btw, you can filter the output for particlular service logs with ls-monitor -f
for example ls-monitor -f com.webos.service.btaudiosrc

@aabytt
Copy link
Author

aabytt commented Jan 17, 2024

also I found this thread on openlgtv discord server. possibly it will help you

@stiw47
Copy link

stiw47 commented Jan 17, 2024

Thank you very much for reminder that this discord server exist. I joined long time ago, but forgot for it at all 😅.
Anyway, I found new command for BT connect, which not require sound output switching, and not producin alert. Just by executing this, device is connected and audio output is switched to BT.

luna-send -f -n 1 luna://com.webos.service.btaudiosrc/connect '{"address": "7b:b1:b9:be:82:fe"}'
Thank you!

@be6ana
Copy link

be6ana commented Apr 9, 2024

I did not get subtitles show on HLS stream . On HTTP/Progressive streams subtitles are showing , but not for HLS . With MKV files works too. Is there any another key to set for make it work ?! Thank you for whole your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment