PlayToConnectionErrorEventArgs Class

提供有关 Error 事件的信息。

语法


/* 有关创建或访问此对象的信息,请参见“备注”。 */

特性

[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06020000)]

成员

PlayToConnectionErrorEventArgs类 具有这些类型的成员:

方法

The PlayToConnectionErrorEventArgs 类 继承这些方法于:Object 类 (C#/VB/C++).

属性

PlayToConnectionErrorEventArgs类 具有这些属性。

属性访问类型说明

Code

只读Gets the error code for a Play To connection error.

Message

只读Gets the error message for a Play To connection error.

 

备注

在 Windows 8 中 Windows 应用商店应用,Code 始终设置为 DeviceError

在 Windows 8.1 中 Windows 应用商店应用,Code 设置为 DeviceErrorProtectedPlaybackFailed。这使得应用可以确定故障是否与内容的媒体保护状态相关。 应用程序可以继续播放播放列表中的下一项或停止。应用程序也可以使用此新 Code 值,以从播放列表中移除所有受保护的音乐。

有关如何在应用程序中使用“播放到”的示例,请参见快速入门:使用对应用程序 (javascript) 的“播放到”快速入门:使用对应用程序 (C#/VB) 的“播放到”

示例


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/>";
}



要求

最低支持客户端

Windows 8 [仅 Windows 应用商店应用程序]

最低支持服务器

Windows Server 2012 [仅 Windows 应用商店应用程序]

命名空间

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

元数据

Windows.winmd

另请参见

PlayToConnection.Error event
示例
“播放到”示例
PlayToReceiver 示例
Media Server 示例

 

 

显示:
© 2014 Microsoft