Skip to content

Focusing on .net Maui Media Element Android fullscreen Video Issue

Notifications You must be signed in to change notification settings

Tuurash/MediaElementModified

Repository files navigation

MediaElementModified

Focusing on .net Maui Media Element Android fullscreen Video Issue Which is not currently supported by .net Maui MediaElement.

Demonstration

Protrait
Full Screen

Overview

A custom Device Orientation Service was created in order to override and manupulate orientation on the go.

namespace MElemetModified.Services;

public partial class DeviceOrientationService{
    public partial void SetDeviceOrientation(DisplayOrientation displayOrientation);
}

and this method needs to inherited into All platforms.

Android specific
namespace MElemetModified.Services;

public partial class DeviceOrientationService{
    private static readonly IReadOnlyDictionary<DisplayOrientation, ScreenOrientation> _androidDisplayOrientationMap =
        new Dictionary<DisplayOrientation, ScreenOrientation>{
            [DisplayOrientation.Landscape] = ScreenOrientation.Landscape,
            [DisplayOrientation.Portrait] = ScreenOrientation.Portrait,
        };

    public partial void SetDeviceOrientation(DisplayOrientation displayOrientation){
        var currentActivity = ActivityStateManager.Default.GetCurrentActivity();
        if (currentActivity is not null)
            if (_androidDisplayOrientationMap.TryGetValue(displayOrientation, out ScreenOrientation screenOrientation))
                currentActivity.RequestedOrientation = screenOrientation;
    }
}
Every other platform specific codes(iOS, Windows, Mac)
namespace MElemetModified.Services;

public partial class DeviceOrientationService{
    public partial void SetDeviceOrientation(DisplayOrientation displayOrientation){}
}
NOTICE all the namespaces. Make sure it is implemented accordingly.

As it can be seen In other platform specific codes the method can be kept empty.

Finally, for in the media visualization page it is necessary to define platform wise condtions as iOS has no issue regarding video fullscreen.

#if ANDROID
        // Make Fullscreen Button visible
#elif IOS
        // keep Fullscreen Button hidden
#endif

About

Focusing on .net Maui Media Element Android fullscreen Video Issue

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages