xamarin / XamarinCommunityToolkit

The Xamarin Community Toolkit is a collection of Animations, Behaviors, Converters, and Effects for mobile development with Xamarin.Forms. It simplifies and demonstrates common developer tasks building iOS, Android, and UWP apps with Xamarin.Forms.
MIT License
1.58k stars 471 forks source link

[Bug] - MediaElement with IsVisible, not display the vídeo #1397

Open gutosys opened 3 years ago

gutosys commented 3 years ago

Description

Steps to Reproduce

  1. Create an MediaPicker and get vídeo
  2. Set item to MediaElement
  3. If has IsVisible control, when has vídeo, the vídeo not appear.

Expected Behavior

Workaround

Reproduction imagery

Reproduction Link

jfversluis commented 3 years ago

Sorry I'm not sure what you mean. What are you setting IsVisible to? Please fill out more details on the template. Is this on iOS, Android, UWP? All? Please share some relevant code and/or a reproduction project.

gutosys commented 3 years ago

Sorry I'm not sure what you mean. What are you setting IsVisible to? Please fill out more details on the template. Is this on iOS, Android, UWP? All? Please share some relevant code and/or a reproduction project.

I intend to show the video on the screen, only after recording the video without taking up space on the screen if it has not been recorded, so IsVisible, controlling the layout.

jfversluis commented 3 years ago

If I understand you correctly what you expect is:

Is that correct? And that is not what is happening now?

Again; some code or a reproduction sample would be greatly appreciated

gutosys commented 3 years ago

If I understand you correctly what you expect is:

  • MediaElement.IsVisible == false, it doesn't take up any space
  • You start loading the video
  • If the loading is complete and you are ready to play it only then set IsVisible to true and it should show up

Is that correct? And that is not what is happening now?

Again; some code or a reproduction sample would be greatly appreciated

Exactly this !

The ViewModel:

  async Task TapVideo()
        {
            if (VideoPath != null)
            {
                await App.Current.MainPage.DisplayAlert("Número máximo de vídeos permitidos: 1", string.Empty, "OK");
                return;
            }

            if (MediaPicker.IsCaptureSupported)
            {
                var result = await MediaPicker.CaptureVideoAsync();

                if (result != null)
                {
                    IsVideo = true;

                    var stream = await result.OpenReadAsync();
                    VideoPath = result.FullPath;
                    fileResultList.Add(result);
                }
            }
        }

The View:

<StackLayout Margin="0,20,0,20" IsVisible="{Binding IsVideo}">
                    <Label

                        Style="{StaticResource LabelTitle}"
                        Text="Vídeo" />
                    <xct:MediaElement
                        AutoPlay="False"
                        HeightRequest="100"
                        HorizontalOptions="Start"
                        Source="{Binding VideoPath}"
                        WidthRequest="300" />
                </StackLayout>

If I use IsVisible, in StackLayout, the vídeo not show anymore, if I use on MediaElement, The video not show anymore. If I remove de IsVisible, the vídeo shows up on the screen.

BuiNhatQuang commented 2 years ago

@gutosys I have experienced the same issue. If the element containing the MediaElement is hidden at initialization, it will not show any video. My workaround at the moment is to let the element be visible at initialization and quickly hide it OnAppearing(). You may need some delay before hiding it so that the MediaElement will properly load the video.

One more thing I have tried is inside the element containing the MediaElement, I make a button and start the video on click and it also works.