question

GenerationContinuum-5900 avatar image
GenerationContinuum-5900 asked ·

Can't Play mp4 File in MediaPlayerElement from https Storage Site

I'm developing a UWP app that has a collection of properties of type MediaSource and each element in the collection is assigned to a source from a URI class:

Video = MediaSource.CreateFromUri(new Uri("https://storage.cloud.google.com/video_bucket/video.mp4";))

The video is supposed to play inside a MediaPlayerElement control. The control's source is bound to the MediaSource property through a view model. The video in each element of the collection changes when the user clicks a Next AppBarButton controlled by a Command Object. The control played each video correctly when I tested the above code using a localhost site on an IIS server I set up:

Video = MediaSource.CreateFromUri(new Uri("http://locahost/images/video.mp4"))

But when I switched to the above https URI, I get the following error from the MediaPlayerElement control-Unidentified file type or invalid path.

Any suggestions on how I can fix this?

windows-uwp
6 comments
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Could you please try to get the source video from the http link using HttpClient? Does it need authentication when you try to access it using HttpClient?


0 Votes 0 · ·

I'm not sure if it needs authentication. I'll need to check with Google Cloud where my mp4 files are stored. As far as HttpClient goes, I'm trying that now. I created an instance of httpclient and generated a class HttpRandomAccessStream to work with it to be used as an argument to the CreateFromStream method of the MediaSource property.

Then I'll assign the CreatFromMediaSource method to the source of the MediaPlayerElement. Hopefully that'll work.

0 Votes 0 · ·
RoyLi-MSFT avatar image RoyLi-MSFT GenerationContinuum-5900 ·

Please kindly let me know about the result.

0 Votes 0 · ·
Show more comments

1 Answer

GenerationContinuum-5900 avatar image
GenerationContinuum-5900 answered ·

I was able to find a solution to my problem. The links I was using to access my mp4 files required authentication. I contacted Google to see if I could get links that didn't require authentication and they gave me API links to my files to use. I replaced the links with the API links and thankfully the files played!

I didn't get a chance to use the HttpClientGetStreamAsync(Uri) method that was suggested, but I'll keep that code in mind. Thanks so much!

Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.