GitXplorerGitXplorer
e

epj.AspectView.Forms

public
3 stars
0 forks
0 issues

Commits

List of commits on branch main.
Unverified
b6521f7f8fc87ca1389f231575e34d8991f6dd11

removed package

eewerspej committed 2 years ago
Unverified
5ff220decb68707b3bc6dc469f3492dd1164552e

small fixes and replaced video player with MediaElement

eewerspej committed 2 years ago
Verified
df0ec1be02249dd16afc9915b1a8c5098e4730d0

updated readme

eewerspej committed 2 years ago
Unverified
48bff1cc137b7e4ccbc202b7023dd82a395d1293

added information to readme

eewerspej committed 2 years ago
Unverified
6328f80ef976d60dd6cde1f841724f6901722c48

cleanup

eewerspej committed 2 years ago
Unverified
e42455560e6efcf3c6e5d829efa7bf9211e65cd5

added screenshots

eewerspej committed 2 years ago

README

The README file for this repository.

epj.AspectView.Forms

License Nuget

A type of ContentView for Xamarin.Forms that resizes itself based on the provided aspect ratio.

Summary

Sometimes, when dealing with video views, I got extremely frustrated, because there was no practical way to keep the video view exactly in the size ratio of the video itself without letterboxing or stretching.

I could set the WidthRequest and HeightRequest properties according to the size ratio of the video, but then I wouldn't have the option to stretch the video across the entire screen width or height using the HorizontalOptions or VerticalOptions.

This is how the AspectView was conceived. It's a container for other ContentViews and always keeps the size ratio that you have set, which means you can box your video view, images or anything else inside of it, provide a size ratio and avoid letterboxing and stretching.

Preview


This looks suspiciously similar like letterboxing, however it's not. In the case of letterboxing, the background would be black while we can actually see the Page background here, which means that we could add other controls and maintain the video's aspect without letterboxing.

Usage

Simply install the package from nuget.org and then use it as follows:

<Grid>

  <forms:AspectView
    AspectRatio="0.5625"
    HorizontalOptions="Fill"
    VerticalOptions="Center">

    <videoPlayer:VideoPlayer
      Source="myvideo.mp4" />

  </forms:AspectView>

</Grid>

If you want to use a 16:9 ratio for videos, you would use 0.5625, like in the example.

Important

The AspectView control uses the HorizontalOptions and VerticalOptions in combination with the AspectRatio property and only works when either the HorizontalOptions or the VerticalOptions property is set to Fill, but not both at the same time.

Note: The AspectRatio must have a value greater than 0.0 and by default is set to 1.0, which means square.

Acknowledgements

Video by Ivan from Pixabay