×
Namespaces

Variants
Actions

媒体键的应用

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

文章
huwell 在 04 Sep 2007 创建
最后由 hamishwillee 在 15 Dec 2011 编辑
  • 设备, 软件 版本:

S60 3rd Edition


  • 详细描述

媒体键的按键事件是无法通过常规手段监测到的,这点和其他按键事件不同。媒体键,如播放/暂停,停止,音量高/低,前进以及后退等键,属于一些S60第三版手机的新特性,不会生成一般的

按键事件,以便被程序框架捕捉,如HandleKeyEventL()以及OfferKeyEventL()。


  • 解决方案

媒体键的按键事件要通过Remote Control API来处理。

下列代码片段演示了如何处理:

CRemConInterfaceSelector
 
CRemConCoreApiTarget
 
MRemConCoreApiTargetObserver
 
Remote Control API requires ReadUserData capability.
 
//------------------------------------------------------------------------------
 
#include <remconcoreapitargetobserver.h> // link against RemConCoreApi.lib
 
#include <remconcoreapitarget.h> // and
 
#include <remconinterfaceselector.h> // RemConInterfaceBase.lib
 
class CMediaKeysTestUi : public CAknAppUi, public MRemConCoreApiTargetObserver
 
{
 
...
 
// From MRemConCoreApiTargetObserver
 
 
 
void MrccatoCommand(TRemConCoreApiOperationId aOperationId,
 
TRemConCoreApiButtonAction aButtonAct);
 
// following functions from MRemConCoreApiTargetObserver are not needed
 
// in this case -> use empty implementations for these:
 
// MrccatoPlay
 
// MrccatoTuneFunction
 
// MrccatoSelectDiskFunction
 
// MrccatoSelectAvInputFunction
 
// MrccatoSelectAudioInputFunction
 
private:
 
CRemConInterfaceSelector* iInterfaceSelector;
 
CRemConCoreApiTarget* iCoreTarget;
 
};
 
void CMediaKeysTestUi::ConstructL()
 
{
 
...
 
iInterfaceSelector = CRemConInterfaceSelector::NewL();
 
iCoreTarget = CRemConCoreApiTarget::NewL(*iInterfaceSelector, *this);
 
iInterfaceSelector->OpenTargetL();
 
}
 
// ----------------------------------------------------------------------------
 
// MrccatoCommand()
 
// Receives events (press/click/release) from the following buttons:
 
// 'Play/Pause', 'Volume Up', 'Volume Down', 'Stop', 'Rewind', 'Forward'
 
// ----------------------------------------------------------------------------
 
void CMediaKeysTestUi::MrccatoCommand(TRemConCoreApiOperationId aOperationId,
 
TRemConCoreApiButtonAction aButtonAct)
 
{
 
TRequestStatus status;
 
switch( aOperationId )
 
{
 
case ERemConCoreApiPausePlayFunction:
 
{
 
switch (aButtonAct)
 
{
 
case ERemConCoreApiButtonPress:
 
// Play/Pause button pressed
 
break;
 
case ERemConCoreApiButtonRelease:
 
// Play/Pause button released
 
break;
 
case ERemConCoreApiButtonClick:
 
// Play/Pause button clicked
 
break;
 
default:
 
// Play/Pause unknown action
 
break;
 
}
 
//Send the response back to Remcon server
 
iCoreTarget->PausePlayFunctionResponse(status, KErrNone);
 
User::WaitForRequest(status);
 
break;
 
}
 
 
 
case ERemConCoreApiStop:
 
{
 
switch (aButtonAct)
 
{
 
// see above (case ERemConCoreApiPausePlayFunction)
 
// for possible actions
 
}
 
iCoreTarget->StopResponse(status, KErrNone);
 
User::WaitForRequest(status);
 
break;
 
}
 
case ERemConCoreApiRewind:
 
{
 
switch (aButtonAct)
 
{
 
// see above for possible actions
 
}
 
iCoreTarget->RewindResponse(status, KErrNone);
 
User::WaitForRequest(status);
 
break;
 
}
 
case ERemConCoreApiForward:
 
{
 
switch (aButtonAct)
 
{
 
// see above for possible actions
 
}
 
iCoreTarget->ForwardResponse(status, KErrNone);
 
User::WaitForRequest(status);
 
break;
 
}
 
case ERemConCoreApiVolumeUp:
 
{
 
switch (aButtonAct)
 
{
 
// see above for possible actions
 
}
 
iCoreTarget->VolumeUpResponse(status, KErrNone);
 
User::WaitForRequest(status);
 
break;
 
}
 
case ERemConCoreApiVolumeDown:
 
{
 
switch (aButtonAct)
 
{
 
// see above for possible actions
 
}
 
iCoreTarget->VolumeDownResponse(status, KErrNone);
 
User::WaitForRequest(status);
 
break;
 
}
 
case ERemConCoreApiFastForward:
 
{
 
switch (aButtonAct)
 
{
 
// see above for possible actions
 
}
 
iCoreTarget->FastForwardResponse(status, KErrNone);
 
User::WaitForRequest(status);
 
break;
 
}
 
case ERemConCoreApiBackward:
 
{
 
switch (aButtonAct)
 
{
 
// see above for possible actions
 
}
 
iCoreTarget->BackwardResponse(status, KErrNone);
 
User::WaitForRequest(status);
 
break;
 
}
 
default:
 
break;
 
}
 
}
 
//------------------------------------------------------------------------------

注意,当按下这些按键,媒体键无法自动重复这些命令,如果需要重复,那需要自己来完成一个(CPeriodic)时间器。


Huwell:难怪vNes这样的模拟器无法捕捉到呢,如果能参照这个成功利用媒体键,那N95将是多么好的游戏机啊,呵呵

This page was last modified on 15 December 2011, at 13:07.
42 page views in the last 30 days.
×