question

WeiWen-3421 avatar image
0 Votes"
WeiWen-3421 asked WeiWen-3421 answered

MediaElement in Xamarin.CommunityToolKit shrinks to the left side on Android

I captured a video using MediaElement in my Xamarin forms app and then I wanted to play it also on MediaElement, but on another content page. The page has a few other components, so the MediaElement can only occupy about 1/3 of the height of the page. However, I still set the width to be about the full width of the page. When MediaElement appeared, it occupied the full width. However, when the video is loaded, it shrinks to the left side. I think this has to do with the aspect ratio. But I already set Aspect to "Fill". I tried all properties I think that may be useful to change this behavior. But nothing works. Please see attachment.
Also, when I click on MediaElement, the play/stop buttons etc. take too much space.

On iOS devices, this is not a problem.



130391-mediaelement.png


dotnet-xamarin
mediaelement.png (36.9 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

WeiWen-3421 avatar image
0 Votes"
WeiWen-3421 answered

@LeonLu-MSFT Setting Aspect to AspectFit moves the image to the center horizontally. AspectFill or Fill will not; they just move the image to the left. One weird behavior I noticed is that if I do not set WidthRequest for the video, it will not have a width, even though I have HorizontalOptions set to CenterAndExpand.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LeonLu-MSFT avatar image
0 Votes"
LeonLu-MSFT answered LeonLu-MSFT edited

Hello,​

Welcome to our Microsoft Q&A platform!

Based on my test, I think this issue is related to the Video source, this video generated by the Camare of Phone(height is bigger than width), If you use this online test Video(https://sec.ch9.ms/ch9/b8f3/6759a97e-053a-458a-a1ec-99497794b8f3/XamarinForms101CompiledBindings_mid.mp4 ). the size is worked as normal.

I think Aspect set to AspectFill is a good choose. Just like a TikTok result.

130614-image.png 130548-image.png

Best Regards,

Leon Lu



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



image.png (199.6 KiB)
image.png (194.5 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.