PlayToConnectionStateChangedEventArgs.PreviousState | previousState property

Applies to Windows and Windows Phone

Gets the previous state before the Play To connection state was changed.

Syntax


public PlayToConnectionState PreviousState { get; }

Property value

Type: PlayToConnectionState

The previous state before the Play To connection state was changed.

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


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


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

PlayToConnectionStateChangedEventArgs
Samples
Play To sample
PlayToReceiver sample
Media Server sample

 

 

Show:
© 2014 Microsoft