PlayToConnectionTransferredEventArgs 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
public ref class PlayToConnectionTransferredEventArgs sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.Deprecated("PlayToConnectionTransferredEventArgs may be altered or unavailable for releases after Windows 10.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class PlayToConnectionTransferredEventArgs final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.Deprecated("PlayToConnectionTransferredEventArgs may be altered or unavailable for releases after Windows 10.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, "Windows.Foundation.UniversalApiContract")]
class PlayToConnectionTransferredEventArgs final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.Deprecated("PlayToConnectionTransferredEventArgs may be altered or unavailable for releases after Windows 10.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class PlayToConnectionTransferredEventArgs
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.Deprecated("PlayToConnectionTransferredEventArgs may be altered or unavailable for releases after Windows 10.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, "Windows.Foundation.UniversalApiContract")]
public sealed class PlayToConnectionTransferredEventArgs
Public NotInheritable Class PlayToConnectionTransferredEventArgs
- 继承
- 属性
Windows 要求
设备系列 |
Windows 10 (在 10.0.10240.0 中引入)
|
API contract |
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)
|
示例
private Windows.Media.PlayTo.PlayToManager ptm =
Windows.Media.PlayTo.PlayToManager.GetForCurrentView();
protected override void OnNavigatedTo(NavigationEventArgs e)
{
ptm.SourceRequested += sourceRequestHandlerWithEvents;
ptm.SourceSelected += sourceSelectedHandler;
}
private void sourceRequestHandlerWithEvents(
Windows.Media.PlayTo.PlayToManager sender,
Windows.Media.PlayTo.PlayToSourceRequestedEventArgs e)
{
try
{
var controller = mediaElement.PlayToSource;
controller.Connection.Error += playToConnectionError;
controller.Connection.StateChanged += playToConnectionStageChanged;
controller.Connection.Transferred += playToConnectionTransferred;
e.SourceRequest.SetSource(controller);
}
catch (Exception ex)
{
messageBlock.Text += "Exception encountered: " + ex.Message + "\n";
}
}
// Called when the user selects a Play To device to stream to.
private void sourceSelectedHandler(
Windows.Media.PlayTo.PlayToManager sender,
Windows.Media.PlayTo.PlayToSourceSelectedEventArgs e)
{
if (mediaElement.Name == "iplayer") {
if (!e.SupportsImage) {
messageBlock.Text += e.FriendlyName + " does not support streaming images. " +
"Please select a different device.";
return;
}
}
if (mediaElement.Name == "vplayer") {
if (!e.SupportsVideo) {
messageBlock.Text += e.FriendlyName + " does not support streaming video. " +
"Please select a different device.";
return;
}
}
if (mediaElement.Name == "aplayer") {
if (!e.SupportsAudio) {
messageBlock.Text += e.FriendlyName + " does not support streaming audio. " +
"Please select a different device.";
return;
}
}
Windows.Storage.Streams.IRandomAccessStream iconStream = e.Icon;
Windows.UI.Xaml.Media.Imaging.BitmapImage iconBitmap =
new Windows.UI.Xaml.Media.Imaging.BitmapImage();
iconBitmap.SetSource(iconStream);
playToDeviceIconImage.Source = iconBitmap;
playToDeviceFriendlyNameBlock.Text = e.FriendlyName;
}
private void playToConnectionError(
Windows.Media.PlayTo.PlayToConnection connection,
Windows.Media.PlayTo.PlayToConnectionErrorEventArgs e)
{
if (e.Code == Windows.Media.PlayTo.PlayToConnectionError.DeviceError ||
e.Code == Windows.Media.PlayTo.PlayToConnectionError.DeviceNotResponding)
{
messageBlock.Text += "Error occurred. Disconnecting.\n";
}
messageBlock.Text += "Error: Message = " + e.Message.ToString() + "\n";
}
private void playToConnectionStageChanged(
Windows.Media.PlayTo.PlayToConnection connection,
Windows.Media.PlayTo.PlayToConnectionStateChangedEventArgs e)
{
messageBlock.Text += "StateChanged: PreviousState = " + e.PreviousState.ToString() + "\n";
messageBlock.Text += "StateChanged: CurrentState = " + e.CurrentState.ToString() + "\n";
}
private void playToConnectionTransferred(
Windows.Media.PlayTo.PlayToConnection connection,
Windows.Media.PlayTo.PlayToConnectionTransferredEventArgs e)
{
messageBlock.Text += "Transferred: PreviousSource = " + e.PreviousSource.ToString() + "\n";
messageBlock.Text += "Transferred: CurrentSource = " + e.CurrentSource.ToString() + "\n";
}
Private ptm As Windows.Media.PlayTo.PlayToManager =
Windows.Media.PlayTo.PlayToManager.GetForCurrentView()
Protected Overrides Sub OnNavigatedTo(e As Navigation.NavigationEventArgs)
AddHandler ptm.SourceRequested, AddressOf sourceRequestHandlerWithEvents
AddHandler ptm.SourceSelected, AddressOf sourceSelectedHandler
End Sub
Private Sub sourceRequestHandlerWithEvents(
sender As Windows.Media.PlayTo.PlayToManager,
e As Windows.Media.PlayTo.PlayToSourceRequestedEventArgs)
Try
Dim controller = mediaElement.PlayToSource
AddHandler controller.Connection.Error, AddressOf playToConnectionError
AddHandler controller.Connection.StateChanged, AddressOf playToConnectionStageChanged
AddHandler controller.Connection.Transferred, AddressOf playToConnectionTransferred
e.SourceRequest.SetSource(controller)
Catch ex As Exception
messageBlock.Text &= "Exception encountered: " & ex.Message & vbCrLf
End Try
End Sub
' Called when the user selects a Play To device to stream to.
Private Sub sourceSelectedHandler(
sender As Windows.Media.PlayTo.PlayToManager,
e As Windows.Media.PlayTo.PlayToSourceSelectedEventArgs)
If mediaElement.Name = "iplayer" Then
If Not e.SupportsImage Then
messageBlock.Text &= e.FriendlyName & " does not support streaming images. " &
"Please select a different device."
Return
End If
End If
If mediaElement.Name = "vplayer" Then
If Not e.SupportsVideo Then
messageBlock.Text &= e.FriendlyName & " does not support streaming video. " &
"Please select a different device."
Return
End If
End If
If mediaElement.Name = "aplayer" Then
If Not e.SupportsAudio Then
messageBlock.Text &= e.FriendlyName & " does not support streaming audio. " &
"Please select a different device."
Return
End If
End If
Dim iconStream = e.Icon
Dim iconBitmap = New Windows.UI.Xaml.Media.Imaging.BitmapImage()
iconBitmap.SetSource(iconStream)
playToDeviceIconImage.Source = iconBitmap
playToDeviceFriendlyNameBlock.Text = e.FriendlyName
End Sub
Private Sub playToConnectionError(
connection As Windows.Media.PlayTo.PlayToConnection,
e As Windows.Media.PlayTo.PlayToConnectionErrorEventArgs)
If e.Code = Windows.Media.PlayTo.PlayToConnectionError.DeviceError OrElse
e.Code = Windows.Media.PlayTo.PlayToConnectionError.DeviceNotResponding Then
messageBlock.Text &= "Error occurred. Disconnecting." & vbCrLf
End If
messageBlock.Text &= "Error: Message = " & e.Message.ToString() & vbCrLf
End Sub
Private Sub playToConnectionStageChanged(
connection As Windows.Media.PlayTo.PlayToConnection,
e As Windows.Media.PlayTo.PlayToConnectionStateChangedEventArgs)
messageBlock.Text &= "StateChanged: PreviousState = " & e.PreviousState.ToString() & vbCrLf
messageBlock.Text &= "StateChanged: CurrentState = " & e.CurrentState.ToString() & vbCrLf
End Sub
Private Sub playToConnectionTransferred(
connection As Windows.Media.PlayTo.PlayToConnection,
e As Windows.Media.PlayTo.PlayToConnectionTransferredEventArgs)
messageBlock.Text &= "Transferred: PreviousSource = " & e.PreviousSource.ToString() & vbCrLf
messageBlock.Text &= "Transferred: CurrentSource = " & e.CurrentSource.ToString() & vbCrLf
End Sub
注解
有关如何在应用程序中使用“播放到”的示例,请参阅 PlayReady DRM。
属性
CurrentSource |
获取已将连接传输到的当前播放到源。 |
PreviousSource |
获取从中传输连接的上一个“播放到”源。 |