Audio Volume Key Event On Symbian: Difference between revisions
No edit summary |
No edit summary |
||
Line 5: | Line 5: | ||
= Getting Audio Volume Key Event on Symbian Devices = | = Getting Audio Volume Key Event on Symbian Devices = | ||
In QML on Symbian devices, audio volume key events are not delivered via Keys.onVolumeDownPressed, Keys.onVolumeUpPressed, or Keys.onPressed. An appropriate solution is wrapping around | In QML on Symbian devices, audio volume key events are not delivered via Keys.onVolumeDownPressed, Keys.onVolumeUpPressed, or Keys.onPressed. An appropriate solution is wrapping around "S60 Remote Control API":http://wiki.forum.nokia.com/index.php/TSS000432_-_Utilising_media_keys by inheriting "MRemConCoreApiTargetObserver":http://library.forum.nokia.com/index.jsp?topic=/S60_5th_Edition_Cpp_Developers_Library/GUID-35228542-8C95-4849-A73F-2B4F082F0C44/sdk/doc_source/reference/reference-cpp/Remote_Control_Framework/MRemConCoreApiTargetObserverClass.html. This is an example code how to do it when building QML/C++ app. Making QML plugin should not be too far from this. | ||
Create a new QML element to deliver the audio volume key event. The S60 Remote Control API actually can get other media key events too. Refer the link above for more detail. | Create a new QML element to deliver the audio volume key event. The S60 Remote Control API actually can get other media key events too. Refer the link above for more detail. | ||
Line 11: | Line 11: | ||
'''MediakeyCaptureItem.h''' | '''MediakeyCaptureItem.h''' | ||
<code> | <code> | ||
#ifndef MediakeyCaptureItem_H | |||
#define MediakeyCaptureItem_H | |||
#include | #include <QDeclarativeItem> | ||
#ifdef Q_WS_S60 | #ifdef Q_WS_S60 | ||
#include <remconcoreapitargetobserver.h> // link against RemConCoreApi.lib | |||
#include <remconcoreapitarget.h> // and | |||
#include <remconinterfaceselector.h> // RemConInterfaceBase.lib | |||
class MediakeyCaptureItemPrivate; | class MediakeyCaptureItemPrivate; | ||
class MediakeyCaptureItem : public QDeclarativeItem | |||
{ | |||
Q_OBJECT | |||
public: | |||
MediakeyCaptureItem(QDeclarativeItem *parent = 0); | |||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |||
signals: | signals: | ||
void volumeDownPressed(); | |||
void volumeUpPressed(); | |||
private: | private: | ||
MediakeyCaptureItemPrivate *d_ptr; | |||
private: // Friend class definitions | |||
friend class MediakeyCaptureItemPrivate; | |||
}; | |||
#endif // Q_WS_S60 | #endif // Q_WS_S60 | ||
#endif // MediakeyCaptureItem_H | |||
</code> | |||
'''MediakeyCaptureItem.cpp''' | '''MediakeyCaptureItem.cpp''' | ||
<code> | <code> | ||
#include "MediaKeyCaptureItem.h" | |||
#ifdef Q_WS_S60 | |||
// A private class to access Symbian RemCon API | // A private class to access Symbian RemCon API | ||
class MediakeyCaptureItemPrivate : public QObject, public MRemConCoreApiTargetObserver | |||
{ | |||
public: | |||
MediakeyCaptureItemPrivate(MediakeyCaptureItem '''parent); | |||
~MediakeyCaptureItemPrivate(); | |||
virtual void MrccatoCommand(TRemConCoreApiOperationId aOperationId, | |||
TRemConCoreApiButtonAction aButtonAct); | |||
private: | |||
CRemConInterfaceSelector''' iInterfaceSelector; | |||
CRemConCoreApiTarget* iCoreTarget; | |||
MediakeyCaptureItem *d_ptr; | |||
}; | |||
// Consructor | // Consructor | ||
MediakeyCaptureItem::MediakeyCaptureItem(QDeclarativeItem *parent): QDeclarativeItem(parent) | |||
{ | |||
d_ptr = new MediakeyCaptureItemPrivate(this); | |||
} | |||
// The paint method | // The paint method | ||
void MediakeyCaptureItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |||
{ | |||
// This item has no visual | |||
} | |||
// Constructor | // Constructor | ||
MediakeyCaptureItemPrivate::MediakeyCaptureItemPrivate(MediakeyCaptureItem *parent): d_ptr(parent) | |||
{ | |||
QT_TRAP_THROWING(iInterfaceSelector = CRemConInterfaceSelector::NewL()); | |||
QT_TRAP_THROWING(iCoreTarget = CRemConCoreApiTarget::NewL(*iInterfaceSelector, '''this)); | |||
iInterfaceSelector->OpenTargetL(); | |||
} | |||
< | // Destructor | ||
MediakeyCaptureItemPrivate::~MediakeyCaptureItemPrivate(){ | |||
delete iInterfaceSelector; | |||
delete iCoreTarget; | |||
} | |||
// Callback when media keys are pressed | |||
void MediakeyCaptureItemPrivate::MrccatoCommand(TRemConCoreApiOperationId aOperationId, | |||
TRemConCoreApiButtonAction aButtonAct) | |||
{ | |||
//TRequestStatus status; | |||
switch( aOperationId ) | |||
{ | |||
case ERemConCoreApiVolumeUp: | |||
emit d_ptr->volumeUpPressed(); | |||
break; | |||
case ERemConCoreApiVolumeDown: | |||
emit d_ptr->volumeDownPressed(); | |||
break; | |||
default: | |||
break; | |||
} | |||
} | |||
#endif // Q_WS_S60 | |||
</code> | |||
In the C++ code, register it into the declarative engine. | |||
<code> | |||
qmlRegisterType<MediakeyCaptureItem>("Mediakey", 1, 0, "MediakeyCapture"); | |||
</code> | |||
Then, you need to add some lines in your .pro file to build. | |||
<code> | |||
symbian{ | |||
INCLUDEPATH ''= MW_LAYER_SYSTEMINCLUDE // Not sure if this is needed… | |||
LIBS''= -L\epoc32\release\armv5\lib -lremconcoreapi | |||
LIBS += -L\epoc32\release\armv5\lib -lremconinterfacebase | |||
} | |||
</code> | |||
In QML, just listen to the signals like this | |||
<code> | |||
import Qt 4.7 | |||
import Mediakey 1.0 | |||
Item{ | |||
… | |||
MediakeyCapture{ | |||
onVolumeDownPressed: console.log('VOLUME DOWN PRESSED ') | |||
onVolumeUpPressed: console.log('VOLUME UP PRESSED ') | |||
} | |||
} | |||
</code> | |||
h2. Troubleshooting | |||
In Qt SDK 1.1 (Windows, Beta and RC) this available only for Symbian^3. But simply copy all | |||
<code> | |||
C:3Qt472\epoc32\release\armv5\lib\rem''' | |||
</code> | |||
to | |||
<code> | |||
C:1Qt472\epoc32\release\armv5\lib | |||
</code> |
Revision as of 10:30, 25 February 2015
English Български
Getting Audio Volume Key Event on Symbian Devices
In QML on Symbian devices, audio volume key events are not delivered via Keys.onVolumeDownPressed, Keys.onVolumeUpPressed, or Keys.onPressed. An appropriate solution is wrapping around "S60 Remote Control API":http://wiki.forum.nokia.com/index.php/TSS000432_-_Utilising_media_keys by inheriting "MRemConCoreApiTargetObserver":http://library.forum.nokia.com/index.jsp?topic=/S60_5th_Edition_Cpp_Developers_Library/GUID-35228542-8C95-4849-A73F-2B4F082F0C44/sdk/doc_source/reference/reference-cpp/Remote_Control_Framework/MRemConCoreApiTargetObserverClass.html. This is an example code how to do it when building QML/C++ app. Making QML plugin should not be too far from this.
Create a new QML element to deliver the audio volume key event. The S60 Remote Control API actually can get other media key events too. Refer the link above for more detail.
MediakeyCaptureItem.h
#ifndef MediakeyCaptureItem_H
#define MediakeyCaptureItem_H
#include <QDeclarativeItem>
#ifdef Q_WS_S60
#include <remconcoreapitargetobserver.h> // link against RemConCoreApi.lib
#include <remconcoreapitarget.h> // and
#include <remconinterfaceselector.h> // RemConInterfaceBase.lib
class MediakeyCaptureItemPrivate;
class MediakeyCaptureItem : public QDeclarativeItem
{
Q_OBJECT
public:
MediakeyCaptureItem(QDeclarativeItem *parent = 0);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
signals:
void volumeDownPressed();
void volumeUpPressed();
private:
MediakeyCaptureItemPrivate *d_ptr;
private: // Friend class definitions
friend class MediakeyCaptureItemPrivate;
};
#endif // Q_WS_S60
#endif // MediakeyCaptureItem_H
MediakeyCaptureItem.cpp
#include "MediaKeyCaptureItem.h"
#ifdef Q_WS_S60
// A private class to access Symbian RemCon API
class MediakeyCaptureItemPrivate : public QObject, public MRemConCoreApiTargetObserver
{
public:
MediakeyCaptureItemPrivate(MediakeyCaptureItem '''parent);
~MediakeyCaptureItemPrivate();
virtual void MrccatoCommand(TRemConCoreApiOperationId aOperationId,
TRemConCoreApiButtonAction aButtonAct);
private:
CRemConInterfaceSelector''' iInterfaceSelector;
CRemConCoreApiTarget* iCoreTarget;
MediakeyCaptureItem *d_ptr;
};
// Consructor
MediakeyCaptureItem::MediakeyCaptureItem(QDeclarativeItem *parent): QDeclarativeItem(parent)
{
d_ptr = new MediakeyCaptureItemPrivate(this);
}
// The paint method
void MediakeyCaptureItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
// This item has no visual
}
// Constructor
MediakeyCaptureItemPrivate::MediakeyCaptureItemPrivate(MediakeyCaptureItem *parent): d_ptr(parent)
{
QT_TRAP_THROWING(iInterfaceSelector = CRemConInterfaceSelector::NewL());
QT_TRAP_THROWING(iCoreTarget = CRemConCoreApiTarget::NewL(*iInterfaceSelector, '''this));
iInterfaceSelector->OpenTargetL();
}
// Destructor
MediakeyCaptureItemPrivate::~MediakeyCaptureItemPrivate(){
delete iInterfaceSelector;
delete iCoreTarget;
}
// Callback when media keys are pressed
void MediakeyCaptureItemPrivate::MrccatoCommand(TRemConCoreApiOperationId aOperationId,
TRemConCoreApiButtonAction aButtonAct)
{
//TRequestStatus status;
switch( aOperationId )
{
case ERemConCoreApiVolumeUp:
emit d_ptr->volumeUpPressed();
break;
case ERemConCoreApiVolumeDown:
emit d_ptr->volumeDownPressed();
break;
default:
break;
}
}
#endif // Q_WS_S60
In the C++ code, register it into the declarative engine.
qmlRegisterType<MediakeyCaptureItem>("Mediakey", 1, 0, "MediakeyCapture");
Then, you need to add some lines in your .pro file to build.
symbian{
INCLUDEPATH ''= MW_LAYER_SYSTEMINCLUDE // Not sure if this is needed…
LIBS''= -L\epoc32\release\armv5\lib -lremconcoreapi
LIBS += -L\epoc32\release\armv5\lib -lremconinterfacebase
}
In QML, just listen to the signals like this
import Qt 4.7
import Mediakey 1.0
Item{
…
MediakeyCapture{
onVolumeDownPressed: console.log('VOLUME DOWN PRESSED ')
onVolumeUpPressed: console.log('VOLUME UP PRESSED ')
}
}
h2. Troubleshooting
In Qt SDK 1.1 (Windows, Beta and RC) this available only for Symbian^3. But simply copy all
C:3Qt472\epoc32\release\armv5\lib\rem'''
to
C:1Qt472\epoc32\release\armv5\lib