locked
MediaElement.Setsource is not working in user control RRS feed

  • Question

  • Hello Team,

    I want to display and run video file in FlipView. For this i have created one User control which contains MediaElement as

    And passing as

    IRandomAccessStream videoStream = await ir.ElementAt(i).OpenAsync(FileAccessMode.ReadWrite);
    UCVideoPlayer uc = new UCVideoPlayer(videoStream, ir.ElementAt(i).ContentType);
    fvPreviewer.Items.Add(uc);

    Here ir is my storagefile Array and fvPreviewer is FlipView control.

    In Usercontrol- name is (UCVideoPlayer)

    Design-

    <MediaElement x:Name="VideoSource" AutomationProperties.Name="VideoSource"   HorizontalAlignment="Center" VerticalAlignment="Center" Height="360" Width="640" AutoPlay="True" PosterSource="Assets/poster.png" IsLooping="True"/>

    Iitialising as

      public UCVideoPlayer(IRandomAccessStream VideoStream, string ContentType)
            {
                this.InitializeComponent();
               VideoSource.SetSource(VideoStream, ContentType);
               VideoSource.Position = new TimeSpan(0, 0, 50000);   
            }

    Can you please guide me for this ? Why this is not getting displayed ?

    Thanks in Advance


    Monday, October 8, 2012 10:21 AM

Answers

  • Regarding the line of code:

    VideoSource.Position = new TimeSpan(0, 0, 50000);
    It will only work after the video has been loaded. So, you should listen to the event CurrentStateChanged and set the Position when the state changes to Playing.

    Pierre Henri K.
    Developer of PressPlay: Video, an advanced video player for Windows 8.

    Monday, October 8, 2012 3:15 PM

All replies

  • The value for

    VideoStream 

    is correct?

    Is not a async/await problem?


    Sara Silva

    Monday, October 8, 2012 1:25 PM
  • Hi Sara,

    Yes this is correct. I have tried with static control on same page.

    Monday, October 8, 2012 1:50 PM
  • I'm pretty sure MediaElement needs to be part of the visualtree before you can load the source. Rearrange your code so setsource is called after added to the FlipView.

    Monday, October 8, 2012 2:48 PM
  • Hi Tim,

    I tried this. Not working....

    Monday, October 8, 2012 2:55 PM
  • Can you share a sample code? is more easy to see the problem.

    Sara Silva

    Monday, October 8, 2012 2:57 PM
  • Regarding the line of code:

    VideoSource.Position = new TimeSpan(0, 0, 50000);
    It will only work after the video has been loaded. So, you should listen to the event CurrentStateChanged and set the Position when the state changes to Playing.

    Pierre Henri K.
    Developer of PressPlay: Video, an advanced video player for Windows 8.

    Monday, October 8, 2012 3:15 PM