PlayToConnection.Error | error event

Applies to Windows and Windows Phone

Occurs when an error is encountered for the Play To connection.

Syntax


function onError(eventArgs) { /* Your code */ }
 
// addEventListener syntax
playToConnection.addEventListener("error", onError);
playToConnection.removeEventListener("error", onError);
 
- or -

playToConnection.onerror = onError;


Event information

Delegate TypedEventHandler<PlayToConnection, PlayToConnectionErrorEventArgs>

Remarks

For an example of how to use Play To in an application, see Quickstart: Using Play To in applications (JavaScript) or Quickstart: Using Play To in applications (C#/VB).

Examples


var ptm = Windows.Media.PlayTo.PlayToManager.getForCurrentView();
ptm.addEventListener("sourcerequested", sourceRequestHandlerWithEvents, false);
ptm.addEventListener("sourceselected", sourceSelectedHandler, false);

function sourceRequestHandlerWithEvents(e) {
    try {
        var controller = mediaElement.msPlayToSource;

        controller.connection.addEventListener("error", playToConnectionError, false);
        controller.connection.addEventListener("stateChanged", playToConnectionStageChanged, false);
        controller.connection.addEventListener("transferred", playToConnectionTransferred, false);

        e.sourceRequest.setSource(controller);

    } catch (ex) {
        id("messageDiv").innerHTML += "Exception encountered: " + ex.message + "<br/>";
    }
}

// Called when the user selects a Play To device to stream to.

function sourceSelectedHandler(e) {
    if (mediaElement.id == "iplayer") {
        if (!e.supportsImage) {
            id("messageDiv").innerHTML += e.friendlyName + " does not support streaming images. " +
                                          "Please select a different device.";
            return;
        }
    }

    if (mediaElement.id == "vplayer") {
        if (!e.supportsVideo) {
            id("messageDiv").innerHTML += e.friendlyName + " does not support streaming video. " +
                                          "Please select a different device.";
            return;
        }
    }

    if (mediaElement.id == "aplayer") {
        if (!e.supportsAudio) {
            id("messageDiv").innerHTML += e.friendlyName + " does not support streaming audio. " +
                                          "Please select a different device.";
            return;
        }
    }


    var iconBlob = window.msWWA.createBlobFromRandomAccessStream(e.icon.contentType, e.icon);
    id("playToDeviceIconImage").src = window.URL.createObjectURL(iconBlob, false);

    id("playToDeviceFriendlyName").innerHTML = e.friendlyName;

    id("playToStatusDiv").style.display = "block";
}

function playToConnectionError(e) {
    if (e.code == Windows.Media.PlayTo.PlayToConnectionError.deviceError |
        e.code == Windows.Media.PlayTo.PlayToConnectionError.deviceNotResponding) {

        id("messageDiv").innerHTML += "Error occurred. Disconnecting.<br/>";
    }

    id("messageDiv").innerHTML += "Error: Message = " + e.message.toString() + "<br/>";
}

function playToConnectionStageChanged(e) {
    id("messageDiv").innerHTML += "StateChanged: PreviousState = " + stateToString(e.previousState) + "<br/>";
    id("messageDiv").innerHTML += "StateChanged: CurrentState = " + stateToString(e.currentState) + "<br/>";
}

function stateToString(state) {
    switch (state) {
        case Windows.Media.PlayTo.PlayToConnectionState.connected:
            return "Connected";
        case Windows.Media.PlayTo.PlayToConnectionState.disconnected:
            return "Disconnected";
        case Windows.Media.PlayTo.PlayToConnectionState.rendering:
            return "Rendering";
    }
}

function playToConnectionTransferred(e) {
    id("messageDiv").innerHTML += "Transferred: PreviousSource = " + e.previousSource.toString() + "<br/>";
    id("messageDiv").innerHTML += "Transferred: CurrentSource = " + e.currentSource.toString() + "<br/>";
}



Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.Media.PlayTo
Windows::Media::PlayTo [C++]

Metadata

Windows.winmd

See also

PlayToConnection
Samples
Play To sample
PlayToReceiver sample
Media Server sample

 

 

Show:
© 2014 Microsoft