locked
how do i open and play a video with FileOpenPicker?

    Question

  • ok, I have my media Element and I have the code to open the file, but how to I put that source to the media element similer to this...

    Dim

    bitmap = NewWindows.UI.Xaml.Media.Imaging.BitmapImage()

    but obviously I want it for a video..? thank you in advance

    Jordan

    Tuesday, February 25, 2014 8:00 PM

Answers

  • Hi,

    There is a simple sample you can refer to:

    In XAML, Create a MediaElement object and give it a Name:

    <MediaElement Name="mediaControl" Height="400" />

    And in code-behind ,use the FileOpenPicker class to select a media file, then to set the Source of the MediaElement to the StorageFile returned from the FileOpenPicker:

    Private Sub SetLocalMedia()
    	Dim openPicker = New Windows.Storage.Pickers.FileOpenPicker()
    
    	openPicker.FileTypeFilter.Add(".wmv")
    	openPicker.FileTypeFilter.Add(".mp4")
    	openPicker.FileTypeFilter.Add(".wma")
    	openPicker.FileTypeFilter.Add(".mp3")
    
    	Dim file = Await openPicker.PickSingleFileAsync()
    
    	Dim stream = Await file.OpenAsync(Windows.Storage.FileAccessMode.Read)
    
    	
    	If file IsNot Nothing Then
    		mediaControl.SetSource(stream, file.ContentType)
    
    		mediaControl.Play()
    	End If
    End Sub

    Also, refer to the links below to get more information:

    How to open local media files using the FileOpenPicker control

    Accessing files with file pickers

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Wednesday, February 26, 2014 3:14 AM