×
Namespaces

Variants
Actions

在QML中调用symbian remote control API 控制音量键

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

代码示例
兼容于
平台:
Symbian

文章
liuting 在 26 Oct 2011 创建
最后由 renlin 在 12 Jul 2012 编辑

Contents

介绍

由于Qt 没有提供函数来响应音量键,所以我们要使用 symbian remote control API 来控制音量键,下面我们将以一个例子来看这些API如何使用。

代码示例

首先我们需要在.PRO 文件中引入如下两个库

LIBS+=-lremconinterfacebase -lremconcoreapi

接下来我们需要定义一个类MediaKeysObserver派生自 QObject 和MRemConCoreApiTargetObserver,在其构造函数中创建 CRemConCoreApiTarget对象

MediaKeysObserver::MediaKeysObserver(QObject*parent):QObject(parent)
 
{
interfaceSelector = CRemConInterfaceSelector::NewL();
coreTarget = CRemConCoreApiTarget::NewL(*interfaceSelector, *this);
interfaceSelector->OpenTargetL();
}

接下来我们需要重写 void MrccatoCommand(TRemConCoreApiOperationId aOperationId ,TRemConCoreApiButtonAction aButtonAct),在其中响应按键消息,根据自己的需要对按键消息进行处理,具体代码如下:

void MediaKeysObserver::MrccatoCommand( TRemConCoreApiOperationId operationId,TRemConCoreApiButtonAction buttonAct) 
{
switch (operationId) {
case ERemConCoreApiPausePlayFunction:
if (buttonAct == ERemConCoreApiButtonClick)
emit mediaKeyClicked(MediaKeysObserver::EPlayPauseKey);
break;
case ERemConCoreApiStop:
if (buttonAct == ERemConCoreApiButtonClick)
emit mediaKeyClicked(MediaKeysObserver::EStopKey);
break;
case ERemConCoreApiRewind:
if (buttonAct == ERemConCoreApiButtonClick)
emit mediaKeyClicked(MediaKeysObserver::EFastRewindKey);
break;
case ERemConCoreApiForward:
if (buttonAct == ERemConCoreApiButtonClick)
emit mediaKeyClicked(MediaKeysObserver::EForwardKey);
break;
case ERemConCoreApiVolumeUp:
if (buttonAct == ERemConCoreApiButtonClick)
emit mediaKeyClicked(MediaKeysObserver::EVolIncKey);
else if (buttonAct == ERemConCoreApiButtonPress)
emit mediaKeyPressed(MediaKeysObserver::EVolIncKey);
else if (buttonAct == ERemConCoreApiButtonRelease)
emit mediaKeyReleased(MediaKeysObserver::EVolIncKey);
break;
case ERemConCoreApiVolumeDown:
if (buttonAct == ERemConCoreApiButtonClick)
emit mediaKeyClicked(MediaKeysObserver::EVolDecKey);
else if (buttonAct == ERemConCoreApiButtonPress)
emit mediaKeyPressed(MediaKeysObserver::EVolDecKey);
else if (buttonAct == ERemConCoreApiButtonRelease)
emit mediaKeyReleased(MediaKeysObserver::EVolDecKey);
break;
case ERemConCoreApiFastForward:
if (buttonAct == ERemConCoreApiButtonClick)
emit mediaKeyClicked(MediaKeysObserver::EFastForwardKey);
else if (buttonAct == ERemConCoreApiButtonPress)
emit mediaKeyPressed(MediaKeysObserver::EFastForwardKey);
else if (buttonAct == ERemConCoreApiButtonRelease)
emit mediaKeyReleased(MediaKeysObserver::EFastForwardKey);
break;
case ERemConCoreApiBackward:
if (buttonAct == ERemConCoreApiButtonClick)
emit mediaKeyClicked(MediaKeysObserver::EBackwardKey);
else if (buttonAct == ERemConCoreApiButtonPress)
emit mediaKeyPressed(MediaKeysObserver::EBackwardKey);
else if (buttonAct == ERemConCoreApiButtonRelease)
emit mediaKeyReleased(MediaKeysObserver::EBackwardKey);
break;
default:
break;
}
}

在本例中,我们的操作是根据不同的按键消息,象QML发送不同的SIGNAL,最后我们看下如何在QML中响应音量键,QML代码如下:

MediaKeysObserver 
{
id: mediakeysobserver
property int key
onMediaKeyClicked: {
console.log("mediakey clicked");
switch (key) {
case MediaKeysObserver.EVolIncKey:
audioPlayer.volume += 0.1
break
case MediaKeysObserver.EVolDecKey:
audioPlayer.volume -= 0.1
break
default: break;
}
}
}

在QML中我们是通过响应音量增减键来控制播放音频的声音大小

代码下载

File:Volumecontrol.zip

相关链接

This page was last modified on 12 July 2012, at 04:50.
268 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×