Audio Volume Key Event On Symbian: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
'''English''' [[Audio Volume Key Event On Symbian Bulgarian|Български]]
[[Category:snippets]]


=Getting Audio Volume Key Event on Symbian Devices=
'''English''' [[Audio_Volume_Key_Event_On_Symbian_Bulgarian|Български]]


In <span class="caps">QML</span> on Symbian devices, audio volume key events are not delivered via Keys.onVolumeDownPressed, Keys.onVolumeUpPressed, or Keys.onPressed. An appropriate solution is wrapping around [http://wiki.forum.nokia.com/index.php/TSS000432_-_Utilising_media_keys S60 Remote Control <span class="caps">API</span>] ''[wiki.forum.nokia.com]'' by inheriting [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 MRemConCoreApiTargetObserver] ''[library.forum.nokia.com]''. This is an example code how to do it when building <span class="caps">QML</span>/C++ app. Making <span class="caps">QML</span> plugin should not be too far from this.
= Getting Audio Volume Key Event on Symbian Devices =


Create a new <span class="caps">QML</span> element to deliver the audio volume key event. The S60 Remote Control <span class="caps">API</span> actually can get other media key events too. Refer the link above for more detail.
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 &quot;S60 Remote Control API&amp;quot;:http://wiki.forum.nokia.com/index.php/TSS000432_-_Utilising_media_keys by inheriting &quot;MRemConCoreApiTargetObserver&amp;quot;: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'''
'''MediakeyCaptureItem.h'''
<code><br />#ifndef MediakeyCaptureItem_H<br />#define MediakeyCaptureItem_H
#include &lt;QDeclarativeItem&amp;gt;
#ifdef Q_WS_S60<br />#include &lt;remconcoreapitargetobserver.h&amp;gt; // link against RemConCoreApi.lib<br />#include &lt;remconcoreapitarget.h&amp;gt; // and<br />#include &lt;remconinterfaceselector.h&amp;gt; // RemConInterfaceBase.lib
class MediakeyCaptureItemPrivate;<br />class MediakeyCaptureItem : public QDeclarativeItem<br />{<br /> Q_OBJECT<br />public:<br /> MediakeyCaptureItem(QDeclarativeItem *parent = 0);<br /> void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
signals:<br /> void volumeDownPressed();<br /> void volumeUpPressed();
private:<br /> MediakeyCaptureItemPrivate *d_ptr;<br />private: // Friend class definitions<br /> friend class MediakeyCaptureItemPrivate;<br />};
#endif // Q_WS_S60<br />#endif // MediakeyCaptureItem_H<br /></code>


'''MediakeyCaptureItem.cpp'''
'''MediakeyCaptureItem.cpp'''


In the C++ code, register it into the declarative engine.
<code><br />#include &quot;MediaKeyCaptureItem.h&amp;quot;<br />#ifdef Q_WS_S60
 
Then, you need to add some lines in your .pro file to build.


In <span class="caps">QML</span>, just listen to the signals like this
// A private class to access Symbian RemCon API<br />class MediakeyCaptureItemPrivate : public QObject, public MRemConCoreApiTargetObserver<br />{<br />public:<br /> MediakeyCaptureItemPrivate(MediakeyCaptureItem '''parent);<br /> ~MediakeyCaptureItemPrivate();<br /> virtual void MrccatoCommand(TRemConCoreApiOperationId aOperationId,<br /> TRemConCoreApiButtonAction aButtonAct);<br />private:<br /> CRemConInterfaceSelector''' iInterfaceSelector;<br /> CRemConCoreApiTarget* iCoreTarget;<br /> MediakeyCaptureItem *d_ptr;<br />};


==Troubleshooting==
// Consructor<br />MediakeyCaptureItem::MediakeyCaptureItem(QDeclarativeItem *parent): QDeclarativeItem(parent)<br />{<br /> d_ptr = new MediakeyCaptureItemPrivate(this);<br />}


In Qt <span class="caps">SDK</span> 1.1 (Windows, Beta and RC) this available only for Symbian^3. But simply copy all <br /> to<br /> will solved compilation problem.
// The paint method<br />void MediakeyCaptureItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)<br />{<br /> // This item has no visual<br />}


===Categories:===
// Constructor<br />MediakeyCaptureItemPrivate::MediakeyCaptureItemPrivate(MediakeyCaptureItem *parent): d_ptr(parent)<br />{<br /> QT_TRAP_THROWING(iInterfaceSelector = CRemConInterfaceSelector::NewL());<br /> QT_TRAP_THROWING(iCoreTarget = CRemConCoreApiTarget::NewL(*iInterfaceSelector, '''this));<br /> iInterfaceSelector-&gt;OpenTargetL();<br />}
<br />// Destructor<br />MediakeyCaptureItemPrivate::~MediakeyCaptureItemPrivate(){<br /> delete iInterfaceSelector;<br /> delete iCoreTarget;<br />}
<br />// Callback when media keys are pressed<br />void MediakeyCaptureItemPrivate::MrccatoCommand(TRemConCoreApiOperationId aOperationId,<br /> TRemConCoreApiButtonAction aButtonAct)<br />{<br /> //TRequestStatus status;<br /> switch( aOperationId )<br /> {<br /> case ERemConCoreApiVolumeUp:<br /> emit d_ptr-&gt;volumeUpPressed();<br /> break;<br /> case ERemConCoreApiVolumeDown:<br /> emit d_ptr-&gt;volumeDownPressed();<br /> break;<br /> default:<br /> break;<br /> }<br />}<br />#endif // Q_WS_S60<br /></code>
<br />In the C++ code, register it into the declarative engine.
<br /><code><br />qmlRegisterType&amp;lt;MediakeyCaptureItem&amp;gt;(&quot;Mediakey&amp;quot;, 1, 0, &quot;MediakeyCapture&amp;quot;);<br /></code>
<br />Then, you need to add some lines in your .pro file to build.
<br /><code><br />symbian{<br /> INCLUDEPATH ''= MW_LAYER_SYSTEMINCLUDE // Not sure if this is needed…<br /> LIBS''= -L\epoc32\release\armv5\lib -lremconcoreapi<br /> LIBS += -L\epoc32\release\armv5\lib -lremconinterfacebase<br />}<br /></code>


* [[:Category:snippets|snippets]]
<br />In QML, just listen to the signals like this
<br /><code><br />import Qt 4.7<br />import Mediakey 1.0<br />Item{
<br /> …
<br /> MediakeyCapture{<br /> onVolumeDownPressed: console.log('VOLUME DOWN PRESSED ')<br /> onVolumeUpPressed: console.log('VOLUME UP PRESSED ')<br /> }<br />}<br /></code>
<br />h2. Troubleshooting
<br />In Qt SDK 1.1 (Windows, Beta and RC) this available only for Symbian^3. But simply copy all<br /><code><br />C:3Qt472\epoc32\release\armv5\lib\rem'''<br /></code><br /> to<br /><code><br />C:1Qt472\epoc32\release\armv5\lib<br /></code>

Revision as of 10:10, 24 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&quot;:http://wiki.forum.nokia.com/index.php/TSS000432_-_Utilising_media_keys by inheriting "MRemConCoreApiTargetObserver&quot;: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

<br />#ifndef MediakeyCaptureItem_H<br />#define MediakeyCaptureItem_H

#include &lt;QDeclarativeItem&amp;gt;

#ifdef Q_WS_S60<br />#include &lt;remconcoreapitargetobserver.h&amp;gt; // link against RemConCoreApi.lib<br />#include &lt;remconcoreapitarget.h&amp;gt; // and<br />#include &lt;remconinterfaceselector.h&amp;gt; // RemConInterfaceBase.lib

class MediakeyCaptureItemPrivate;<br />class MediakeyCaptureItem : public QDeclarativeItem<br />{<br /> Q_OBJECT<br />public:<br /> MediakeyCaptureItem(QDeclarativeItem *parent = 0);<br /> void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);

signals:<br /> void volumeDownPressed();<br /> void volumeUpPressed();

private:<br /> MediakeyCaptureItemPrivate *d_ptr;<br />private: // Friend class definitions<br /> friend class MediakeyCaptureItemPrivate;<br />};

#endif // Q_WS_S60<br />#endif // MediakeyCaptureItem_H<br />

MediakeyCaptureItem.cpp

<br />#include &quot;MediaKeyCaptureItem.h&amp;quot;<br />#ifdef Q_WS_S60

// A private class to access Symbian RemCon API<br />class MediakeyCaptureItemPrivate : public QObject, public MRemConCoreApiTargetObserver<br />{<br />public:<br /> MediakeyCaptureItemPrivate(MediakeyCaptureItem '''parent);<br /> ~MediakeyCaptureItemPrivate();<br /> virtual void MrccatoCommand(TRemConCoreApiOperationId aOperationId,<br /> TRemConCoreApiButtonAction aButtonAct);<br />private:<br /> CRemConInterfaceSelector''' iInterfaceSelector;<br /> CRemConCoreApiTarget* iCoreTarget;<br /> MediakeyCaptureItem *d_ptr;<br />};

// Consructor<br />MediakeyCaptureItem::MediakeyCaptureItem(QDeclarativeItem *parent): QDeclarativeItem(parent)<br />{<br /> d_ptr = new MediakeyCaptureItemPrivate(this);<br />}

// The paint method<br />void MediakeyCaptureItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)<br />{<br /> // This item has no visual<br />}

// Constructor<br />MediakeyCaptureItemPrivate::MediakeyCaptureItemPrivate(MediakeyCaptureItem *parent): d_ptr(parent)<br />{<br /> QT_TRAP_THROWING(iInterfaceSelector = CRemConInterfaceSelector::NewL());<br /> QT_TRAP_THROWING(iCoreTarget = CRemConCoreApiTarget::NewL(*iInterfaceSelector, '''this));<br /> iInterfaceSelector-&gt;OpenTargetL();<br />}
<br />// Destructor<br />MediakeyCaptureItemPrivate::~MediakeyCaptureItemPrivate(){<br /> delete iInterfaceSelector;<br /> delete iCoreTarget;<br />}
<br />// Callback when media keys are pressed<br />void MediakeyCaptureItemPrivate::MrccatoCommand(TRemConCoreApiOperationId aOperationId,<br /> TRemConCoreApiButtonAction aButtonAct)<br />{<br /> //TRequestStatus status;<br /> switch( aOperationId )<br /> {<br /> case ERemConCoreApiVolumeUp:<br /> emit d_ptr-&gt;volumeUpPressed();<br /> break;<br /> case ERemConCoreApiVolumeDown:<br /> emit d_ptr-&gt;volumeDownPressed();<br /> break;<br /> default:<br /> break;<br /> }<br />}<br />#endif // Q_WS_S60<br />


In the C++ code, register it into the declarative engine.


<br />qmlRegisterType&amp;lt;MediakeyCaptureItem&amp;gt;(&quot;Mediakey&amp;quot;, 1, 0, &quot;MediakeyCapture&amp;quot;);<br />


Then, you need to add some lines in your .pro file to build.


<br />symbian{<br /> INCLUDEPATH ''= MW_LAYER_SYSTEMINCLUDE // Not sure if this is needed…<br /> LIBS''= -L\epoc32\release\armv5\lib -lremconcoreapi<br /> LIBS += -L\epoc32\release\armv5\lib -lremconinterfacebase<br />}<br />


In QML, just listen to the signals like this


<br />import Qt 4.7<br />import Mediakey 1.0<br />Item{
<br /> 
<br /> MediakeyCapture{<br /> onVolumeDownPressed: console.log('VOLUME DOWN PRESSED ')<br /> onVolumeUpPressed: console.log('VOLUME UP PRESSED ')<br /> }<br />}<br />


h2. Troubleshooting


In Qt SDK 1.1 (Windows, Beta and RC) this available only for Symbian^3. But simply copy all

<br />C:3Qt472\epoc32\release\armv5\lib\rem'''<br />


to

<br />C:1Qt472\epoc32\release\armv5\lib<br />