PlayToManager.SourceSelected | sourceselected event

Applies to Windows only

Occurs when a Play To source element has been selected.

Syntax


public event TypedEventHandler<PlayToManager, PlayToSourceSelectedEventArgs> SourceSelected

Event information

Delegate TypedEventHandler<PlayToManager, PlayToSourceSelectedEventArgs>

Remarks

In a Play To–enabled app, the user selects the Devices charm (or the Play To UI) to stream audio, video, or images from the app to a target device. The SourceSelected event is fired after the user has selected a target device. If the user exits the Devices charm or the Play To UI without selecting a target device, the SourceSelected event isn't fired.

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

None supported

Namespace

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

Metadata

Windows.winmd

See also

PlayToManager
Samples
Play To sample
PlayToReceiver sample
Media Server sample

 

 

Show:
© 2014 Microsoft