HTML5 video not working on MAUI WebView

See original GitHub issue

Description

If I want to add video in my MAUI Blazor App I have a problem with rendering this video on iOS. On Android works well. I think the problem is in BlazorWebView component.

UPDATE This applies to all MAUI webviews, so is not Blazor-specific.

Steps to Reproduce

  1. Create a new blank .NET MAUI Blazor App

  2. Add some sample video mp4 file into the wwwroot/videos folder image

  3. Replace content of Index.razor page with content below:

@page "/"

<h1>Hello, world!</h1>

Welcome to your new app.

<video autoplay muted loop playsinline class="slideContent">
    <source src="videos/TRIMOTERM.mp4" type="video/mp4">
</video>
  1. Run app on Android. All good. image

  2. Run app on iPhone 12 (iOS 15.2) and nothing is shown where video could be. image

Version with bug

Preview 13 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iPhone 12 iOS 15.2, Xcode 13.2.1, VS 17.2.0 Preview 1.0

Did you find any workaround?

No

Relevant log output

Nothing

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:28 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
Redthcommented, Nov 2, 2022

In the meantime, if you’re looking to make this work today, in .NET 7, you can customize the platform view factory or WebViewHandler like this:

#if IOS || MACCATALYST
Microsoft.Maui.Handlers.WebViewHandler.PlatformViewFactory = (handler) =>
{
	var config = Microsoft.Maui.Platform.MauiWKWebView.CreateConfiguration();
	config.AllowsAirPlayForMediaPlayback = true;
	config.AllowsInlineMediaPlayback = true;
	config.AllowsPictureInPictureMediaPlayback = true;
	config.MediaTypesRequiringUserActionForPlayback = WebKit.WKAudiovisualMediaTypes.None;
	
	var wv = new Microsoft.Maui.Platform.MauiWKWebView(
		CoreGraphics.CGRect.Empty,
		handler as Microsoft.Maui.Handlers.WebViewHandler,
		config);

	return wv;
};
#endif
3reactions
jfversluiscommented, Feb 21, 2022

Thank you for that! Had a quick look and here is the weird thing… If I add the controls attribute to the video to show the controls and actually click the play button it works just fine. So it seems like there is something preventing it from playing automatically. Not sure if this is a bug on our side then though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issue with displaying the camera stream in an inline video ...
I am creating a . net maui application blazor hosted. This app uses RecordRTC. js to access the camera.
Read more >
In a .NET Maui Blazor application, can you play a video ...
In a .NET Maui Blazor application, can you play a video (using the video HTML5 element) by pointing the source attribute directly to...
Read more >
WebView - .NET MAUI
This article explains how to use the .NET MAUI WebView to display remote web pages, local HTML files, and HTML strings.
Read more >
The HTML5 service worker and WebAssembly - .NET MAUI ...
- [Instructor] For this video, we are going to use a new, very simple MAUI Blazor application that does one thing: navigate out...
Read more >
Managing WebView objects
Android provides several APIs to help you manage the WebView objects that display web content in your app. This page describes how to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found