PlayToReceiver 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表播放目標。
public ref class PlayToReceiver sealed
/// [Windows.Foundation.Metadata.Activatable(65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class PlayToReceiver final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
class PlayToReceiver final
[Windows.Foundation.Metadata.Activatable(65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class PlayToReceiver
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
public sealed class PlayToReceiver
function PlayToReceiver()
Public NotInheritable Class PlayToReceiver
- 繼承
- 屬性
Windows 需求
裝置系列 |
Windows 10 (已於 10.0.10240.0 引進)
|
API contract |
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)
|
應用程式功能 |
privateNetworkClientServer
|
備註
您可以使用 PlayToReceiver 類別來建立自定義軟體 Play To 接收者,這是網路上計算機的數位媒體轉譯器。 您可以在應用程式中包含 PlayToReceiver 物件,以處理與 Play To 用戶端電腦的通訊,然後使用您自己的媒體元素或控件播放或顯示從這些電腦串流的內容。
PlayToReceiver 類別的成員包含下列各項:
- FriendlyName 屬性,可在網路上公告時識別播放收件者的名稱。
- 識別播放收件者支援之媒體類型的屬性: SupportsAudio、 SupportsVideo、 SupportsImage。
- StartAsync 方法,會啟動播放收件者,並在網路上將其公告為數位媒體轉譯器。 StopAsync 方法會停止播放收件者,並停止在網路上廣告。
- 當您從電腦收到媒體串流時所發生的 SourceChangeRequested 事件, 以及當播放至用戶端電腦要求動作的事件,例如磁碟區變更,或串流媒體的播放位置變更時所發生的事件:CurrentTimeChangeRequested、MuteChangeRequested、PauseRequested、PlayRequested、StopRequested、VolumeChangeRequested、TimeUpdateRequested。
- 當您的 Play To 接收者發生變更時,您可以呼叫以通知播放到用戶端的方法:NotifyDurationChange、NotifyEnded、NotifyError、NotifyLoadedMetadata、NotifyPaused、NotifyPlaying、NotifyRateChange、NotifySeeked、NotifySeeking、NotifyStopped、NotifyTimeUpdate、NotifyVolumeChange。
在 [播放到] 中,影片會從目前的位置開始。 如果您想要從頭開始影片,只要建立 [播放到] 連線,就立即搜尋影片的開頭。
如需建立軟體播放收件者的範例,請參閱 媒體傳播。
Windows.Media.PlayTo.PlayToReceiver receiver;
Windows.System.Display.DisplayRequest display;
Windows.UI.Core.CoreDispatcher dispatcher;
bool seeking = false;
private async void StartReceiverButton_Click(object sender, RoutedEventArgs e)
{
try
{
dispatcher = Window.Current.CoreWindow.Dispatcher;
if (receiver == null)
{
receiver = new Windows.Media.PlayTo.PlayToReceiver();
}
// Add Play To Receiver events and properties
receiver.CurrentTimeChangeRequested += receiver_CurrentTimeChangeRequested;
receiver.MuteChangeRequested += receiver_MuteChangeRequested;
receiver.PauseRequested += receiver_PauseRequested;
receiver.PlaybackRateChangeRequested += receiver_PlaybackRateChangeRequested;
receiver.PlayRequested += receiver_PlayRequested;
receiver.SourceChangeRequested += receiver_SourceChangeRequested;
receiver.StopRequested += receiver_StopRequested;
receiver.TimeUpdateRequested += receiver_TimeUpdateRequested;
receiver.VolumeChangeRequested += receiver_VolumeChangeRequested;
receiver.FriendlyName = "Sample Play To Receiver";
receiver.SupportsAudio = false;
receiver.SupportsVideo = true;
receiver.SupportsImage = false;
// Add MediaElement events
VideoPlayer.CurrentStateChanged += VideoPlayer_CurrentStateChanged;
VideoPlayer.MediaEnded += VideoPlayer_MediaEnded;
VideoPlayer.MediaFailed += VideoPlayer_MediaFailed;
VideoPlayer.MediaOpened += VideoPlayer_MediaOpened;
VideoPlayer.RateChanged += VideoPlayer_RateChanged;
VideoPlayer.SeekCompleted += VideoPlayer_SeekCompleted;
VideoPlayer.VolumeChanged += VideoPlayer_VolumeChanged;
// Advertise the receiver on the local network and start receiving commands
await receiver.StartAsync();
// Prevent the screen from locking
if (display == null)
display = new Windows.System.Display.DisplayRequest();
display.RequestActive();
StatusTextBlock.Text = "'" + receiver.FriendlyName + "' started.";
}
catch
{
receiver = null;
StatusTextBlock.Text = "Failed to start receiver.";
}
}
private async void StopReceiverButton_Click(object sender, RoutedEventArgs e)
{
try
{
if (receiver != null)
{
await receiver.StopAsync();
if (display != null)
display.RequestRelease();
// Remove Play To Receiver events
receiver.CurrentTimeChangeRequested -= receiver_CurrentTimeChangeRequested;
receiver.MuteChangeRequested -= receiver_MuteChangeRequested;
receiver.PauseRequested -= receiver_PauseRequested;
receiver.PlaybackRateChangeRequested -= receiver_PlaybackRateChangeRequested;
receiver.PlayRequested -= receiver_PlayRequested;
receiver.SourceChangeRequested -= receiver_SourceChangeRequested;
receiver.StopRequested -= receiver_StopRequested;
receiver.TimeUpdateRequested -= receiver_TimeUpdateRequested;
receiver.VolumeChangeRequested -= receiver_VolumeChangeRequested;
// Remove MediaElement events
VideoPlayer.Pause();
VideoPlayer.CurrentStateChanged -= VideoPlayer_CurrentStateChanged;
VideoPlayer.MediaEnded -= VideoPlayer_MediaEnded;
VideoPlayer.MediaFailed -= VideoPlayer_MediaFailed;
VideoPlayer.MediaOpened -= VideoPlayer_MediaOpened;
VideoPlayer.RateChanged -= VideoPlayer_RateChanged;
VideoPlayer.SeekCompleted -= VideoPlayer_SeekCompleted;
VideoPlayer.VolumeChanged -= VideoPlayer_VolumeChanged;
StatusTextBlock.Text = "Stopped '" + receiver.FriendlyName + "'.";
}
}
catch
{
StatusTextBlock.Text = "Failed to stop '" + receiver.FriendlyName + "'.";
}
}
Private receiver As Windows.Media.PlayTo.PlayToReceiver
Private display As Windows.System.Display.DisplayRequest
Private seeking As Boolean = False
Private Async Sub StartReceiverButton_Click()
Try
If receiver Is Nothing Then
receiver = New Windows.Media.PlayTo.PlayToReceiver()
End If
' Add Play To Receiver events and properties
AddHandler receiver.CurrentTimeChangeRequested, AddressOf receiver_CurrentTimeChangeRequested
AddHandler receiver.MuteChangeRequested, AddressOf receiver_MuteChangeRequested
AddHandler receiver.PauseRequested, AddressOf receiver_PauseRequested
AddHandler receiver.PlaybackRateChangeRequested, AddressOf receiver_PlaybackRateChangeRequested
AddHandler receiver.PlayRequested, AddressOf receiver_PlayRequested
AddHandler receiver.SourceChangeRequested, AddressOf receiver_SourceChangeRequested
AddHandler receiver.StopRequested, AddressOf receiver_StopRequested
AddHandler receiver.TimeUpdateRequested, AddressOf receiver_TimeUpdateRequested
AddHandler receiver.VolumeChangeRequested, AddressOf receiver_VolumeChangeRequested
receiver.FriendlyName = "Sample Play To Receiver"
receiver.SupportsAudio = False
receiver.SupportsVideo = True
receiver.SupportsImage = False
' Add MediaElement events
AddHandler VideoPlayer.CurrentStateChanged, AddressOf VideoPlayer_CurrentStateChanged
AddHandler VideoPlayer.MediaEnded, AddressOf VideoPlayer_MediaEnded
AddHandler VideoPlayer.MediaFailed, AddressOf VideoPlayer_MediaFailed
AddHandler VideoPlayer.MediaOpened, AddressOf VideoPlayer_MediaOpened
AddHandler VideoPlayer.RateChanged, AddressOf VideoPlayer_RateChanged
AddHandler VideoPlayer.SeekCompleted, AddressOf VideoPlayer_SeekCompleted
AddHandler VideoPlayer.VolumeChanged, AddressOf VideoPlayer_VolumeChanged
' Advertise the receiver on the local network and start receiving commands
Await receiver.StartAsync()
' Prevent the screen from locking
If display Is Nothing Then
display = New Windows.System.Display.DisplayRequest()
display.RequestActive()
StatusTextBlock.Text = "'" & receiver.FriendlyName & "' started."
End If
Catch
receiver = Nothing
StatusTextBlock.Text = "Failed to start receiver. "
End Try
End Sub
Private Async Sub StopReceiverButton_Click()
Try
If receiver IsNot Nothing Then
Await receiver.StopAsync()
If display IsNot Nothing Then display.RequestRelease()
' Remove Play To Receiver events
RemoveHandler receiver.CurrentTimeChangeRequested, AddressOf receiver_CurrentTimeChangeRequested
RemoveHandler receiver.MuteChangeRequested, AddressOf receiver_MuteChangeRequested
RemoveHandler receiver.PauseRequested, AddressOf receiver_PauseRequested
RemoveHandler receiver.PlaybackRateChangeRequested, AddressOf receiver_PlaybackRateChangeRequested
RemoveHandler receiver.PlayRequested, AddressOf receiver_PlayRequested
RemoveHandler receiver.SourceChangeRequested, AddressOf receiver_SourceChangeRequested
RemoveHandler receiver.StopRequested, AddressOf receiver_StopRequested
RemoveHandler receiver.TimeUpdateRequested, AddressOf receiver_TimeUpdateRequested
RemoveHandler receiver.VolumeChangeRequested, AddressOf receiver_VolumeChangeRequested
' Remove MediaElement events
VideoPlayer.Pause()
RemoveHandler VideoPlayer.CurrentStateChanged, AddressOf VideoPlayer_CurrentStateChanged
RemoveHandler VideoPlayer.MediaEnded, AddressOf VideoPlayer_MediaEnded
RemoveHandler VideoPlayer.MediaFailed, AddressOf VideoPlayer_MediaFailed
RemoveHandler VideoPlayer.MediaOpened, AddressOf VideoPlayer_MediaOpened
RemoveHandler VideoPlayer.RateChanged, AddressOf VideoPlayer_RateChanged
RemoveHandler VideoPlayer.SeekCompleted, AddressOf VideoPlayer_SeekCompleted
RemoveHandler VideoPlayer.VolumeChanged, AddressOf VideoPlayer_VolumeChanged
StatusTextBlock.Text = "Stopped '" & receiver.FriendlyName & "'."
End If
Catch
StatusTextBlock.Text = "Failed to stop '" & receiver.FriendlyName & "'."
End Try
End Sub
只要視訊或音樂正在播放至接收者或影像持續傳送給播放收件者,PlayTo 應用程式將不會暫停。 應用程式在顯示目前影像之後大約要傳送 10 秒,大約 10 秒才能在目前影像結束之後傳送下一個音訊或視訊。
注意
這個類別不是敏捷的,這表示您必須考慮其線程模型和封送處理行為。 如需詳細資訊,請參閱線程和封送處理 (C++/CX) 和在多線程環境中使用 Windows 執行階段 物件 (.NET) 。
建構函式
PlayToReceiver() |
建立播放收件者的新實例。 |
屬性
FriendlyName |
取得或設定 Play To 目標的顯示名稱。 |
Properties |
取得播放收件者的一組自定義屬性。 |
SupportsAudio |
取得或設定值,這個值表示播放至目標是否支援音訊。 |
SupportsImage |
取得或設定值,這個值表示播放至目標是否支援影像。 |
SupportsVideo |
取得或設定值,這個值表示播放至目標是否支持視訊。 |
方法
NotifyDurationChange(TimeSpan) |
通知播放收件者音訊或視訊播放的持續時間已變更。 |
NotifyEnded() |
通知播放收件者音訊或視訊播放已結束。 |
NotifyError() |
通知播放收件者顯示或播放媒體時發生錯誤。 |
NotifyLoadedMetadata() |
通知播放收件者媒體的元數據已完成載入。 |
NotifyPaused() |
通知播放收件者音訊或視訊播放已暫停。 |
NotifyPlaying() |
通知播放收件者音訊或視訊播放已啟動。 |
NotifyRateChange(Double) |
通知播放收件者音訊或視訊播放的速率已變更。 |
NotifySeeked() |
通知播放收件者音訊或視訊播放專案已在新的播放位置啟動。 |
NotifySeeking() |
通知播放收件者,音訊或視訊播放專案正在搜尋新的播放位置。 |
NotifyStopped() |
通知播放收件者音訊或視訊播放已停止。 |
NotifyTimeUpdate(TimeSpan) |
通知播放收件者音訊或視訊播放的時間位置已變更。 |
NotifyVolumeChange(Double, Boolean) |
通知播放收件者音訊或視訊播放的音量已變更。 |
StartAsync() |
開始接收播放至命令。 |
StopAsync() |
停止接收播放至命令。 |
事件
CurrentTimeChangeRequested |
發生於播放的時間位置變更時。 |
MuteChangeRequested |
發生於音訊已靜音或未靜音時。 |
PauseRequested |
發生於音訊或視訊播放已暫停時。 |
PlaybackRateChangeRequested |
發生於音訊或視訊播放的速率變更時。 |
PlayRequested |
當音訊或視訊播放開始時發生。 |
SourceChangeRequested |
發生於播放收件者的來源媒體已變更時。 |
StopRequested |
發生於對播放收件者提出要求以停止播放串流媒體時。 |
TimeUpdateRequested |
發生於目前播放位置變更時。 |
VolumeChangeRequested |
發生於來源音訊或視訊的音量已變更時。 |