Fix Autoplay Videos for Android .NET MAUI Blazor Hybrid

Paul Willy Hammer
3 min read2 days ago

If you want to play videos in the background in Blazor Hybrid on Android, it won’t work right away. Definitely keep reading if you have the same problem.

How did I come across the problem?

Currently, I am working on an app. We have a login screen that features a beautiful video background.

There were also many issues with iOS.

I primarily tested the app using iOS deployment. There, I encountered several problems related to playing videos in the background. For completeness, I’ll list the links here again:

Video hangs on iOS devices:
https://medium.com/@paulwillyhammer/blazor-hybrid-net-8-playing-videos-in-the-background-ui-thread-issue-and-an-ugly-solution-2fcfa767bb91

What is the problem with Android, then?

In HTML, you can instruct the video element to perform an autoplay so that the video plays immediately when the Blazor page is opened. Unfortunately, this doesn’t work. I discovered the reason through thorough research: the Android WebView prevents actions like htmlElement.play() via JavaScript. In my search for a solution, I thought it might work if I used the typical JavaScript setTimeout with a function call to “play” the video element. This…

--

--

Paul Willy Hammer

PWH, a senior software developer, excels in creating efficient .NET applications, always eager to share insights and best practices in software development.