xamarin 中的视频播放器旋转(Android)

问题描述 投票:0回答:1

我是 xamarin 社区工具包中的 usn MediaElement (https://learn.microsoft.com/en-us/xamarin/community-toolkit/),我需要旋转它。我试图做到这一点只是改变旋转属性:

<!--left:--> 
                <xct:MediaElement x:Name="vidLeft" Grid.Column="0" Grid.Row="1" IsLooping="True" Scale="2" ShowsPlaybackControls="False" />
<!-right:-->               
                <xct:MediaElement x:Name="vidRight" Grid.Column="2" Grid.Row="1" IsLooping="True" Scale="2" ShowsPlaybackControls="False" Rotation="90"/>

但它无法正常工作:https://i.stack.imgur.com/pcDGA.jpg

那么,有什么想法可以做到这一点吗?

顺便说一句,我可以使用任何其他具有视频旋转功能的视频播放器。

感谢您的帮助!

android xml xamarin xamarin.forms xamarin.android
1个回答
0
投票

使用 Toolkit 旋转媒体文件时,旋转属性出现问题。而且我没有找到它的官方文档。

要解决此问题,您可以尝试旋转屏幕来旋转媒体文件。

您可以使用依赖服务旋转屏幕。

创建接口:

 public interface IOrientationService
{
    void Landscape();
    void Portrait();
}

安卓:

public class OrientationService : IOrientationService
{
public void Landscape()
{
    ((Activity)Forms.Context).RequestedOrientation = ScreenOrientation.Landscape;
}

public void Portrait()
{
    ((Activity)Forms.Context).RequestedOrientation = ScreenOrientation.Portrait;
}
}

iOS:

 public class OrientationService : IOrientationService
{
 public void Landscape()
{
    AppDelegate appDelegate = (AppDelegate)UIApplication.SharedApplication.Delegate;
    appDelegate.allowRotation = true;

    UIDevice.CurrentDevice.SetValueForKey(new NSNumber((int)UIInterfaceOrientation.LandscapeLeft), new NSString("orientation"));   
}

public void Portrait()
{
    AppDelegate appDelegate = (AppDelegate)UIApplication.SharedApplication.Delegate;
    appDelegate.allowRotation = true;

    UIDevice.CurrentDevice.SetValueForKey(new NSNumber((int)UIInterfaceOrientation.Portrait), new NSString("orientation"));
}
}

依赖服务的使用可以参考MS的文档。 https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/dependency-service/introduction

您可以在 GitHub 中发布有关

MediaElement
轮换的问题。 https://github.com/xamarin/XamarinCommunityToolkit/issues

© www.soinside.com 2019 - 2024. All rights reserved.