openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.9k stars 3.59k forks source link

[lgwebos] mediaPlayer does not accept NextPreviousType #7278

Closed optmax closed 4 years ago

optmax commented 4 years ago

Expected Behavior

Within a mediaPlayer clicking the Next icon should move to the next track Similarly clicking Previous icon should move to the previous track (Pause and Play work as PlayPauseType input is accepted)

Current Behavior

==> /var/log/openhab2/openhab.log <== 2020-04-02 21:25:18.529 [DEBUG] [ebos.internal.handler.LGWebOSHandler] - handleCommand(lgwebos:WebOSTV:a3c77ba0-654a-0982-c480-f726662f05b8:mediaPlayer,NEXT) 2020-04-02 21:25:18.534 [INFO ] [.lgwebos.internal.MediaControlPlayer] - Only accept PlayPauseType, RewindFastforwardType, RefreshType. Type was class org.eclipse.smarthome.core.library.types.NextPreviousType.

Possible Solution

Steps to Reproduce (for Bugs)

  1. Create an Item Player with Channel mediaPlayer
  2. Send a command NEXT or Previous (either clicking within Controls on Paper UI or create a Sstemap including a Player and click within Basic UI or create a rule that sends command)

Context

Control apps on webOS TV

Your Environment

Raspberry Pi 3 ARMv7 Raspbian GNU/Linux 9 (stretch)

openHAB 2.5.4 Build #74

LG web OS Binding 2.5.4.202004020414

Item Player TV_Player { channel="lgwebos:WebOSTV:a3c77ba0-654a-0982-c480-f726662f05b8:mediaPlayer"}

Wihin a Rule TV_Player.sendCommand( NEXT )

==> /var/log/openhab2/openhab.log <== 2020-04-02 21:25:18.529 [DEBUG] [ebos.internal.handler.LGWebOSHandler] - handleCommand(lgwebos:WebOSTV:a3c77ba0-654a-0982-c480-f726662f05b8:mediaPlayer,NEXT) 2020-04-02 21:25:18.534 [INFO ] [.lgwebos.internal.MediaControlPlayer] - Only accept PlayPauseType, RewindFastforwardType, RefreshType. Type was class org.eclipse.smarthome.core.library.types.NextPreviousType.

lolodomo commented 4 years ago

@sprehn : do previous and next commands exist in the API? I don't see these commands in the code. Is the webOS API public or was it reverse engineered?

sprehn commented 4 years ago

It is all reverse engineered based on connectsdk.

sprehn commented 4 years ago

option A) These are the events we can send via the API. "ssap://media.controls/play"; "ssap://media.controls/pause"; "ssap://media.controls/stop"; "ssap://media.controls/rewind"; "ssap://media.controls/fastForward";

we could simply give it a try, for example with "ssap://media.controls/next"

No access to my TV at the moment, so cannot try.

option B) TV_Player.sendCommand( RIGHT )

optmax commented 4 years ago

@sprehn: Thank you for getting back to me and indeed for all your work on the lgwebos binding.

I am self-isolating due to the coronavirus at the moment and set myself a project to get to grips with openHAB to control my entertainment system. It is proving to be a most enjoyable way to isolate :-)

Option A Any pointers as to how to implement ssap within my project?

Option B I have tried TV_Player.sendCommand( RIGHT ) from inside a rule called "skip" It generates this error 2020-04-03 23:40:14.540 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'skip': The name 'RIGHT' cannot be resolved to an item or type

But... For the PLEX app on my webOSTV TV_RCButton.sendCommand("RIGHT") via a rcButton channel works :-)

Thanks for the pointer.

lolodomo commented 4 years ago

I updated the code to use ssap://media.controls/previous and ssap://media.controls/next but it does not work:

10:35:44.447 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'TvPlayer' received command PREVIOUS
10:35:44.499 [DEBUG] [webos.internal.handler.LGWebOSHandler] - handleCommand(lgwebos:WebOSTV:tv:mediaPlayer,PREVIOUS)
10:35:44.511 [TRACE] [ebos.internal.handler.LGWebOSTVSocket] - Message [out]: {"type":"request","id":15,"uri":"ssap://media.controls/previous"}
10:35:44.539 [TRACE] [ebos.internal.handler.LGWebOSTVSocket] - Message [in]: {"type":"error","id":15,"error":"404 no such service or method","payload":{}}
10:35:44.556 [DEBUG] [ebos.internal.handler.LGWebOSTVSocket] - Error: {"type":"error","id":15,"error":"404 no such service or method","payload":{}}
10:35:44.565 [DEBUG] [g.lgwebos.internal.BaseChannelHandler] - MediaControlPlayer received error response: 404 no such service or method
10:35:50.442 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'TvPlayer' received command NEXT
10:35:50.512 [DEBUG] [webos.internal.handler.LGWebOSHandler] - handleCommand(lgwebos:WebOSTV:tv:mediaPlayer,NEXT)
10:35:50.522 [TRACE] [ebos.internal.handler.LGWebOSTVSocket] - Message [out]: {"type":"request","id":16,"uri":"ssap://media.controls/next"}
10:35:50.542 [TRACE] [ebos.internal.handler.LGWebOSTVSocket] - Message [in]: {"type":"error","id":16,"error":"404 no such service or method","payload":{}}
10:35:50.553 [DEBUG] [ebos.internal.handler.LGWebOSTVSocket] - Error: {"type":"error","id":16,"error":"404 no such service or method","payload":{}}
10:35:50.562 [DEBUG] [g.lgwebos.internal.BaseChannelHandler] - MediaControlPlayer received error response: 404 no such service or method

Failing too with ssap://media.controls/nextTrack

PS: I tested for the first time play/pause when the Music app is running and it works as expected.

lolodomo commented 4 years ago

Now that I checked the code and tested the media player feature, I can see that something is missing in the code, the state of the channels mediaPlayer and mediaStop is never updated. As an example, when PLAY command is pushed by the user and you receive a positive feedback, you should update the state of these 2 channels accordingly. I will try to improove that.

optmax commented 4 years ago

@lolodomo: Thank you for investigating. I am of no help looking at the source code side of things but if there is any testing I can help with in openHAB then do let me know.

lolodomo commented 4 years ago

@optmax : unfortunately, this is clearly not obvious to guess what are the SSAP commands to be used for PREVIOUS/NEXT commands. We are not sure they even exist. I just tried the most probable ones but without any success.

optmax commented 4 years ago

@lomodomo: I have just tried the Next and Previous buttons in the LG TV Plus app on Android and they don’t work! So maybe LG never implemented the code? Thanks for investigating.

lolodomo commented 4 years ago

@sprehn : if sendRCButton is working with LEFT and RIGHT, we could simply use it as commands for the player item. I am going to test that.

lolodomo commented 4 years ago

Tested but not really "reliable" because it depends on what was the previous mouse position.

optmax commented 4 years ago

I've been experimenting with an RCButton sequence and find that its slightly more reliable if you also have a sequence to step back through the PLEX App to the Home page before changing to another input.

I found that starting the 'escape sequnce' with TV_RCButton.sendCommand("BLUE") helps if the screensaver is active

memphi2 commented 4 years ago

Hi, I've connected my LG today via Alexa V3 skill and openhab. I found out, that if i say "NEXT" it's not working, but if i say "FASTFORWARD" it is working! Two different commands are send to openhab:

Item 'TV_Bed_Player' received command NEXT Result: Only accept PlayPauseType, RewindFastforwardType, RefreshType.........

Item 'TV_Bed_Player' received command FASTFORWARD Result: TV_Bed_Player predicted to become FASTFORWARD TV_Bed_Player changed from PLAY to FASTFORWARD

The Player item in openhab sends "NEXT". If it would send "FASTWORDWARD" the buttons will work. Regards, Olli

memphi2 commented 4 years ago

This simple workarourd will do the job:

rule "Set working Player FASTFORWARD Command"
when 
    TV_Player received command NEXT 
then 
    TV_Player.sendCommand(FASTFORWARD)
end

rule "Set working Player PREVIOUS Command"
when 
    TV_Player received command PREVIOUS 
then 
    TV_Player.sendCommand(REWIND)
end
lolodomo commented 4 years ago

The normal commands for the openHAB player widget are play/pause, previopus and next.