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++]

Metadata

Windows.winmd

請參閱

PlayToConnection.Error event
範例
播放至範例
PlayToReceiver 範例
媒體伺服器範例

 

 

顯示:
© 2015 Microsoft