Miracast card

A Miracast card can be invoked to discover and establish a connection to a nearby Miracast device. You can invoke the Miracast card in two modes: play on and show on.

Showing content on a Miracast device

In ShowOn mode, the application is not aware of the streaming. The content is streamed to a Miracast device in the native resolution of the BlackBerry device. Here are the invocation attributes you use to invoke the Miracast card to show your content on a Miracast device:

Attribute Value
Target ID

sys.miracastviewer

Action

bb.action.VIEW

MIME type application/vnd.rim.miracast.showon

The following code sample shows how you can invoke the Miracast card in ShowOn mode:
void ShowOn() {
    // ...
  
    InvokeRequest request;
    request.setTarget("sys.miracastviewer");
    request.setAction("bb.action.VIEW");
    request.setMimeType("application/vnd.rim.miracast.showon");
  
    invokeManager->invoke(request);
    // ...
  
}
Here's the same code sample for Qt:
...
actions: {
    ActionItem {
        id: showOn
        title: "Show on"
    imageSource: "asset:///images/ic_show_on.png"
        ActionBar.placement: ActionBarPlacement.OnBar
        onTriggered: {
            _application.ShowOn()
        }
    }
}

Playing content on a Miracast device

In PlayOn mode, your application renders content to a Miracast device at a resolution that can be different from the native resolution of the BlackBerry device. Here are the invocation attributes you use to invoke the Miracast card to play your content on a Miracast device:

Attribute Value
Target ID

sys.miracastviewer

Action

bb.action.VIEW

MIME type application/vnd.rim.miracast.playon

The following code sample shows how you can invoke the Miracast card in PlayOn mode:
void PlayOn() {
    // ...
 
    InvokeRequest request;
    request.setTarget("sys.miracastviewer");
    request.setAction("bb.action.SHARE");
    request.setMimeType("application/vnd.rim.miracast.playon");
 
    invokeManager->invoke(request)
    // ...
 
}
Here's the same code sample for Qt:
...
actions: {
    ActionItem {
        id: playOn
        title: "Play on"
        imageSource: "asset:///images/ic_play_on.png"
        ActionBar.placement: ActionBarPlacement.OnBar
        onTriggered: {
            _application.PlayOn()
        }
    }
}

Controlling a Miracast session

You can control a Miracast session by using the session ID. If the Miracast Card is invoked in the PlayOn mode, a session ID is generated by the Miracast service and passed through the card to the calling application. To receive the session ID, you must connect the invokeManager to receive data from the cardDoneMessage using the invokeManager object's childCardDone() signal and onChildCardDone() slot.
// If any Q_ASSERT statement(s) indicate that the slot failed to connect to 
// the signal, make sure you know exactly why this has happened. This is not
// normal, and will cause your app to stop working!!
bool connectResult;

// Since the variable is not used in the app, this is added to avoid a 
// compiler warning.
Q_UNUSED(connectResult);

connectResult = QObject::connect(invokeManager, 
    SIGNAL(childCardDone(const bb::system::CardDoneMessage&)), 
    this,
    SLOT(onChildCardDone(const bb::system::CardDoneMessage&)));
                                 
// This is only available in Debug builds.
Q_ASSERT(connectResult); 

// ...
 
void onChildCardDone(bb::system::CardDoneMessage &message) {
    // Retrieve the session ID from Miracast Card
    QString sessionId = message.data();
    
    // ... 
}

Last modified: 2013-12-21

comments powered by Disqus