Forum Xamarin.Forms

Rotation for videoplayer in xamarn

TTWTTW Member ✭✭
edited May 18 in Xamarin.Forms
xmlns:video="clr-namespace:proj.Controls.Video"
 <video:VideoPlayer x:Name="videoPlayer" AreTransportControlsEnabled = "False"
                           Grid.Row="0" AutoPlay="False"/>
 private void Rotate_Clicked(object sender, EventArgs e)
        {
            if (videoPlayer.sRotate == false)
            {
                videoPlayer.sRotate = true;
            }
            else
            {
                videoPlayer.sRotate = false;
            }
        }

The videoPlayer.sRotate is Enable in Android and IOSis not work.Is something other need for IOS or Any Other way for rotate the videoplayer

Answers

  • LeonLuLeonLu Member, Xamarin Team Xamurai
    edited May 18

    Do you custom a VideoPlayer and add sRotate properties?

    If so, can you share a code about your custom VideoPlayer?If you used videoPlayer.RotateTo(90); to rotate the videoPlayer. If you rotate this videoPlayer, it just rotate this control, but the video cannot be rotated like this screenshot.

  • TTWTTW Member ✭✭
    edited May 19

    @LeonLu said:
    Do you custom a VideoPlayer and add sRotate properties?

    If so, can you share a code about your custom VideoPlayer?If you used videoPlayer.RotateTo(90); to rotate the videoPlayer. If you rotate this videoPlayer, it just rotate this control, but the video cannot be rotated like this screenshot.

    In my controls

     public bool sRotate
            {
                set { SetValue(sRotateProperty, value); }
                get { return (bool)GetValue(sRotateProperty); }
            }
    
    In Ios Videoplayer rendender 
    protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs args)
            {
                base.OnElementPropertyChanged(sender, args);
                if (Element.sRotate)
                {
                    UIDevice.CurrentDevice.SetValueForKey(new NSNumber((int)UIInterfaceOrientation.LandscapeRight), new NSString("orientation"));
                }
                else
                {
                    UIDevice.CurrentDevice.SetValueForKey(new NSNumber((int)UIInterfaceOrientation.Portrait), new NSString("orientation"));
                }
    }
    I think _**UIDevice.CurrentDevice.SetValueForKey(new NSNumber((int)UIInterfaceOrientation.LandscapeRight), new NSString("orientation"));
    //  doesn't work in ios 
    
    For android the rotation is work
    if (Element.sRotate)
                {
                    activity.RequestedOrientation = Android.Content.PM.ScreenOrientation.Landscape;
                }
                else
                {
                    activity.RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;
                }
    
    
  • LeonLuLeonLu Member, Xamarin Team Xamurai

    Is your screen orientation locked?

    And please open your Info.plist, check if you have enable these settings.

Sign In or Register to comment.