locked
How to play a mixture of videos and images using "PlayTo" in a metro app? RRS feed

  • Question

  • I have a metro app which has to play a mixture of images and videos in a flip view as and when the user flips through the collection. I am able to stream either the images or the videos. But not a mixture, since the PlayToSourceRequest.SetSource can either be image.PlayToSource or mediaElement.PlayToSouce. How can I change the PlayToSource property based on the file type without t
    private async void PlayToManager_SourceRequested(PlayToManager sender, PlayToSourceRequestedEventArgs args)
            {
                try
                {
                    _isPlayToEnabled = true;
    
                    PlayToSourceRequest request = args.SourceRequest;
                    PlayToSourceDeferral deferral = request.GetDeferral();
                    PlayToSource controller = null;
    
                    await _dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                    () =>
                    {                    
                        if (mediaElement is Image)
                        {
                            OnPlayToError("Media element is an IMAGE");
                            controller = ((Image)mediaElement).PlayToSource;
                        }
                        else
                        {
                            OnPlayToError("Media element is a VIDEO");
                            controller = ((MediaElement)mediaElement).PlayToSource;
                        }
    
                        controller.Connection.Error += OnConnectionError;
                        controller.Connection.StateChanged += OnConnectionStateChanged;
                        controller.Connection.Transferred += OnConnectionTransferred;
                        request.SetSource(controller);
    
                        deferral.Complete();
                    });
                }
                catch (Exception ex)
                {
                    OnPlayToError(ex.Message);
                }
            }

    he user going to the Devices charm?
    Wednesday, August 29, 2012 6:00 PM

Answers

  • Hello,

    You said: "I need to programmatically change the PlayToSource without the user going to the devices charm."

    This is not currently possible. When you currently cannot share a play to source between different instances of the play to enabled controls.

    Thanks,

    James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Friday, September 14, 2012 10:36 PM
    Moderator

All replies

  • Hello,

    I think you can follow Rob's solution in this thread
    http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/139f6abb-9528-49cb-b97d-19422d5ad89e

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, August 30, 2012 8:33 AM
  • Hi Jesse, 

    Thanks for the response. But this not exactly what I want as my question was regarding PlayTo and I will have to typecast the control as Image/MediaElement in the code when a playTo source is requested.

    To put it in a simple way, I have an image control and a media element control in the form (both visible). On enabling play to, the user should be able to toggle between displaying the image and the video in the PlayTo device.

    -Soorya

    Tuesday, September 4, 2012 5:41 PM
  • Hi Soorya,

    Please don't spam the forum by posting the same question multiple times in several threads.. Please post one thread per question, and one question per thread.

    I don't believe you can achieve what you want: each PlayTo instance will come from a single source and cannot be toggled between multiple sources. I've pointed our media specialist at this thread to confirm.

    --Rob

    Wednesday, September 5, 2012 11:01 PM
    Moderator
  • Thanks Rob.

    Right now the native app in Win8 seems to be able to play both videos and images on selecting play to. Could you please throw some light on how can this be achieved if the toggling is out of the options.

    Wednesday, September 5, 2012 11:11 PM
  • Thanks Rob.

    Right now the native app in Win8 seems to be able to play both videos and images on selecting play to.

    If you are able to play both videos and images using playto, what is your problem? Does your code not work as expected? Are you getting an error? I would expect that switching the source would cause the current connection to close and require a new connection to the device. Is this the problem you are seeing?

    -James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Wednesday, September 5, 2012 11:53 PM
    Moderator
  • May be I wasn't clear. I am NOT able to play both images and videos. The screen has an image and a video. When the user selects a PlayTo device using the Devices charm, I set the play to source as the Image and the image is displayed in the device. Where as, on a button click the video has to be played in the device instead of the image for which I need to programmatically change the PlayToSource without the user going to the devices charm. I am unable to programmatically switch the source control from Image to MediaElement as I believe this can be done only in the SourceRequested event which is triggered on selecting the devices charm by the user.

    Thursday, September 6, 2012 12:25 AM
  • Hello,

    You said: "I need to programmatically change the PlayToSource without the user going to the devices charm."

    This is not currently possible. When you currently cannot share a play to source between different instances of the play to enabled controls.

    Thanks,

    James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Friday, September 14, 2012 10:36 PM
    Moderator
  • Thanks for the response James.

    Hope this feature is enabled in the nearest future. Any idea how the native photo app in Win8 is able to play both images and videos to the same play to device?

    Monday, September 17, 2012 6:29 PM
  • I did not try myself, but I think this is very well possible.

    Check the documentation on PlayNext() and Next property of PlayToSource:

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.media.playto.playtosource.playnext.aspx

    If I understand that correctly, it should be possible to assign the PlayToSource of your MediaElement to the PlayToSource.Next property of the Image you are showing in the first place. Then on the button click you call PlayToSource.PlayNext() on the Image to switch to the MediaElement's PlayToSource. This way you can chain and stream multiple different PlayToSources to one PlayTo device.


    Edit: Just saw that this was answered on a different thread you opened. Since this really seems to work, please set this as the (single) answer of this thread, so others also find this solution.
    • Proposed as answer by Lukas F Monday, November 5, 2012 11:43 AM
    • Edited by Lukas F Monday, November 5, 2012 11:45 AM
    Monday, November 5, 2012 11:42 AM