RSATom / QmlVlc

[ABANDONED] libvlc wrapper for Qt Quick 2/Qml
Other
139 stars 56 forks source link

Using remote control #34

Closed kevkha closed 9 years ago

kevkha commented 9 years ago

Hi Sergey,

Can you provide guidance to use a remote control in Qt QML with your library? I tried below and with Qt.Key_Play and Qt.Key_Pause but nothing seems to work.

Thanks in advance.

Example:

Keys.onPressed: {
    if ( (event.key === Qt.Key_MediaPlay) || (event.key === Qt.Key_MediaPause) ) {
        event.accepted = true;
        vlcPlayer.togglePause();
    }
}
RSATom commented 9 years ago

What OS do you use?

kevkha commented 9 years ago

I will target Ubuntu first but would like to have this feature working cross platform. Is it possible?

RSATom commented 9 years ago

yes, It just could have issues on Mac OS X That's why I asked.

to enable handling keyboard events you have to add focus: true; to Qml item

RSATom commented 9 years ago
focus: true;
Keys.onPressed: {
    console.log( event.key );
}
kevkha commented 9 years ago

I do have focus: true; set. When I map keys on keyboard work but not from remote control. Nothing get printed out. Per http://doc.qt.digia.com/qt-maemo/qt.html I tried to add

#include Qt>
to main.cpp but still no joy.

RSATom commented 9 years ago

Hm, I don't know how remote control works. Where I can read about it? btw, we use Qt 5, so better read docs related to this version, not Qt 4 - it could be very different in some aspects.

RSATom commented 9 years ago

Maybe you have to translate signals from remote control to key press by yourself? If yes, I could give you some hints about how to emulate keyboard events.

kevkha commented 9 years ago

Yes, please assist. I think that's what I lack of. In Ubuntu we can use irw to get the key name and code and use xdotool for keys mapping. Do you know such tool like irw for Windows?

RSATom commented 9 years ago

no, didn't ever work with remote controls. But hear about http://winlirc.sourceforge.net/

RSATom commented 9 years ago

So, when you will find the way to get events from IR within c++ code - you could emulate keyboard events as it was done there: https://github.com/RSATom/WebChimera/blob/master/src/Mac/Chimera_Mac.mm#L400 (it's part of WebChimera plugin for Mac)

kevkha commented 9 years ago

I did some diggings and found this old post http://forum.qt.io/topic/611/how-to-generate-an-event-to-esc-escape-f1-and-such-keys/14 which discussed about mapping RC keys. My C++ skill is very rusty and not sure how to start from here. Can you help on sample class? Thanks.

RSATom commented 9 years ago

It seems there are two parts in this task:

  1. get commands from WinLIRC
  2. translate commands to key events end send them to QuickViewer.

how to do second part I gave link above. About first part - look this http://prdownloads.sourceforge.net/lirc/xirw-0.4.2.tar.bz2

kevkha commented 9 years ago

Thank you. I used irw to retrieve codes and commands in Ubuntu

000000037ff07be9 00 KEY_PLAY mceusb
000000037ff07be7 00 KEY_PAUSE mceusb
000000037ff07be4 00 KEY_AGAIN mceusb
000000037ff07be5 00 KEY_NEXT mceusb
000000037ff07be6 00 KEY_STOP mceusb
000000037ff07bdc 00 KEY_BACK mceusb

If I am going to hard code this in c++ for QmlVlc does that mean another user with a different IR can't control the program because the commands might be different? What is the best approach for the program to work with any IR control? Is that when mapping with irexec or xirw come into play?

RSATom commented 9 years ago

If I am going to hard code this in c++ for QmlVlc does that mean another user with a different IR can't control the program because the commands might be different?

I think it's very possible, but don't sure.

Is that when mapping with irexec or xirw come into play?

I think, yes.

kevkha commented 9 years ago

Ok thanks. I will give it a try. It would be nice to have a library for standard IR control in QmlVlc. Are you planning to add this feature in the near future?

RSATom commented 9 years ago

No, I don't plan it, but it worth to think about it.

kevkha commented 9 years ago

I have good news. I use a different IR branded Rosewill RRC-126 (MCE fully compatible) and it works out of the box for both Windows and Ubuntu. There is no need to add IR c++ code. I only used the same QML Qt.Key_* mentioned above. I'm happy with this result. Thanks again.

RSATom commented 9 years ago

How do you get IR commands from WinLIRC in your application? over sockets?

kevkha commented 9 years ago

I'm not using WinLIRC at all. None of the devices suit with my USB IR so I could not get a config.cf created. In qml I just use.

FocusScope {
    id: mainScope
    focus: true
    Keys.onPressed: {
        //vlc control
        if ( (event.key === Qt.Key_MediaPlay) || (event.key === Qt.Key_Key_MediaPause) || (event.key === Qt.Key_Play) || (event.key === Qt.Key_Pause) ) {
            event.accepted = true;
            controlRect.visible = !controlRect.visible;
            vlcPlayer.togglePause();
            //DEBUG
            console.log("Key " + event.key + " detected");
        }
   }
}
RSATom commented 9 years ago

What USB IR do you use? Rosewill RRC-126? Did you install any software for it?

kevkha commented 9 years ago

Yes, the RRC-126. I did not install any software. The driver is taken care by the OS (Windows 7).

RSATom commented 9 years ago

Hm... interesting, didn't know Widows has drivers for IR controls.

RSATom commented 9 years ago

It seems all signal translation made inside driver, so application just get it as keyboard key presses. Then it will work for all IR controls supported by supplied by Windows drivers.

kevkha commented 9 years ago

Yeah I was thinking of the hard way. I should add Qt.Key_Space to cover keyboard. You may close this issue. Thanks.