MediaKeyWatcher

#include <bb/multimedia/MediaKeyWatcher>

To link against this class, add the following line to your .pro file: LIBS += -lbbmultimedia

Represents a hardware media key and provides notification.

If two MediaKeyWatcher objects reference the same MediaKey then the last one to connect the signal will receive the notification until all the slots are disconnected from that signal. A short press is defined as being less than 650ms in duration and a long press is 650ms or greater in duration.

There are two different notification types for this media key watcher. MediaKeyNotification.Clicked is the default and results in the respective press signals to be called when the hardware media key is released. MediaKeyNotification.Threshold causes press to be signaled once the earliest connected signal threshold is reached (0ms for shortPress and 650ms for longPress). If both shortPress and longPress are connected the shortPress signal will only be emitted.

When all slots are disconnected from a signal, notification is returned to the last MediaKeyWatcher object that is connected to the signal of the same media key. Otherwise the default action from now playing is triggered.

C++ example:

MediaKeyWatcher keyWatcher(MediaKey::VolumeUp);
...
QObject::connect(&keyWatcher, SIGNAL(longPress(bb::multimedia::MediaKey::Type)), this, SLOT(onLongPress());
QObject::connect(&keyWatcher, SIGNAL(shortPress(bb::multimedia::MediaKey::Type)), this, SLOT(onShortPress());

QML example:

import bb.multimedia 1.0
...
attachedObjects: [
  MediaKeyWatcher {
      id: keyWatcher
      key: MediaKey.VolumeUp

      onLongPress: {
        // do something
      }

      onShortPress: {
        // do something
      }
  }
]

Since:

BlackBerry 10.0.0

Public Functions Index

MediaKeyWatcher (MediaKey::Type key, QObject *parent=0)
MediaKeyWatcher (QObject *parent=0)
virtual ~MediaKeyWatcher ()
MediaKey::Typekey () const
MediaKeyNotification::Typenotification () const

Public Slots Index

voidsetNotification (bb::multimedia::MediaKeyNotification::Type notification)

Signals Index

voidlongPress (bb::multimedia::MediaKey::Type key)
voidnotificationChanged (bb::multimedia::MediaKeyNotification::Type notification)
voidshortPress (bb::multimedia::MediaKey::Type key)

Properties

bb::multimedia::MediaKey::Type key[read-only]

Represents any of the media button types.

Since:

BlackBerry 10.0.0

bb::multimedia::MediaKeyNotification::Type notification

Represents any of the media button types.

Since:

BlackBerry 10.1.0

Public Functions

MediaKeyWatcher (

Constructs a MediaKey object.

Create and associates a MediaKey with a specific media button.

Parameters
key

The MediaKey::Type to watch.

parent

An optional parameter to specify the parent of this QObject.

Since:

BlackBerry 10.0.0

MediaKeyWatcher (

Constructs a MediaKey object.

Create and associates a MediaKey with MediaKey::None.

Parameters
parent

An optional parameter to specify the parent of this QObject.

Since:

BlackBerry 10.0.0

virtual~MediaKeyWatcher ()

Destructor.

Since:

BlackBerry 10.0.0

MediaKey::Type key ()

Provides the MediaKey associated with this watcher.

Return:

the media type providing notifications.

Since:

BlackBerry 10.0.0

MediaKeyNotification::Type notification ()

Provides the MediaKeyNotification associated with this key watcher.

Return:

the media type notification type.

Since:

BlackBerry 10.1.0

Public Slots

void setNotification (

Used to set the media key notification type.

When the notification type MediaKeyNotification::Clicked is set the media key signals will not fire until the hardware key has been released. For MediaKeyWatcher::Threshold the media key signal will fire as soon as the press threshold has been reached for the given length. In this case the press signal will only occur for the earliest connected signal.

Parameters
notification

The media key notification type to use.

Since:

BlackBerry 10.1.0

Signals

void longPress (

Signal emitted for a media key long press.

This signal is emitted when the associated media button has been pressed for more than 700ms.

Since:

BlackBerry 10.0.0

void notificationChanged (

Signal emitted when the notification type has changed.

Since:

BlackBerry 10.1.0

void shortPress (

Signal emitted for a media key short press.

This signal is emitted when the associated media button is pressed for less than 350ms.

Since:

BlackBerry 10.1.0