In a .NET Maui Blazor application, can you play a video (using the video HTML5 element) by pointing the source attribute directly to the path of a video file on the user's file system?

Yusuf Groenewald 0 Reputation points
2023-07-11T07:39:42.73+00:00

I have a .NET Maui Blazor application and want to play an mp4 video within a razor page of the application by pointing the source of the HTML5 video element directly to the path of the video file on the user's file system, but can't get it to work. Is this possible?

When I include the mp4 video file in the actual .NET Maui Blazor project (under wwwroot/videos) and then point the HTML5 video element to it then the video plays. But this is not my requirement. I want the user to select the video file (using FilePicker) and then play the video inside the .NET Maui Blazor application.

This works (where the testvideo.mp4 file is included in the project under wwwroot/videos):

<video controls="controls" width="800px" height="462px">
    <source src="videos/testvideo.mp4" type="video/mp4">
</video>

This does not work:

<video controls="controls" width="800px" height="462px">
    <source src="C:\videos\testvideo.mp4" type="video/mp4">
</video>

This does not work either:

<video controls="controls" width="800px" height="462px">
    <source src="C:/videos/testvideo.mp4" type="video/mp4">
</video>
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,595 questions
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,582 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 66,226 Reputation points
    2023-07-11T19:02:56.78+00:00

  2. Mahdi Rastegari 0 Reputation points
    2023-10-23T20:52:13.37+00:00

    The answer is simple by the general rules of the browser, they don't have access to file storage directly. it would help if you used the input (HTML element) to select the file rather than the machine or robot. it does make sense as I don't want browser access to my data.

    but the question is, should BlazorWebView also have this policy? is there any way to bypass it?


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.