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.59k stars 475 forks source link

[Bug] MediaElement not showing up #400

Open Mikilll94 opened 4 years ago

Mikilll94 commented 4 years ago

Description

Steps to Reproduce

  1. Run this project MediaElementTest.zip

  2. As you can see MediaElement (video) is not showing up.

media_element_not_showing

Expected Behavior

MediaElement (video) should be visible.

Actual Behavior

MediaElement (video) is not visible. I was testing on Android.

Basic Information

jsuarezruiz commented 4 years ago

I've been testing your repro sample. To have the MediaElement working, some details are missing. The first point is the experimental flag. MediaElement is in preview and you need the use the following flag: Device.SetFlags(new string[] { "MediaElement_Experimental" }); Then, if you want to auto play the video, you can use the Autoplay property. If you want to start playback by pressing the Play button, you need to handle the Click event and use the MediaElement Play method.

void Button_Clicked(object sender, System.EventArgs e)
{
     MediaPlayer.Play();
}
Captura de pantalla 2020-03-02 a las 13 50 20

Please, test when you can the attached sample (is your sample modified): Issue9785.zip

Mikilll94 commented 4 years ago

@jsuarezruiz You are right that I forgot to add Device.SetFlags(new string[] { "MediaElement_Experimental" }); in Android project. After adding this I have noticed that the media player is still not displaying. Then I have changed this:

        <MediaElement Source="https://sec.ch9.ms/ch9/5d93/a1eab4bf-3288-4faf-81c4-294402a85d93/XamarinShow_mid.mp4"
                      ShowsPlaybackControls="True" VerticalOptions="StartAndExpand"/>

to this

        <MediaElement Source="https://sec.ch9.ms/ch9/5d93/a1eab4bf-3288-4faf-81c4-294402a85d93/XamarinShow_mid.mp4"
                      ShowsPlaybackControls="True" VerticalOptions="FillAndExpand"/>

So when you have VerticalOptions="StartAndExpand" it is not working but if change to VerticalOptions="FillAndExpand" it is working.

JesperMLC commented 4 years ago

I had the same issue now have implemented: VerticalOptions="FillAndExpand"

Zangl commented 4 years ago

I only see an issue with no playback when the video source is a local resource on android.

legyas commented 4 years ago

I only see an issue with no playback when the video source is a local resource on android.

I have the same issue, but for some reason It works after hot reloading the page

Gogsi commented 4 years ago

As a temporary workaround I manually play the video and resize it to refresh the view

Device.StartTimer(TimeSpan.FromSeconds(1), () =>
            {
                videoPlayer.Play();

                videoPlayer.ScaleTo(0.99f);
                videoPlayer.ScaleTo(1.00f);

                return false;
            });
thisisthekap commented 4 years ago

We also can confirm this issue on Android 10 (API Level 29) with the video loaded from local resources.

jfversluis commented 3 years ago

This is still happening with the Toolkit version. There is a couple of workarounds already mentioned.

Still good to take a look what is going on and hopefully fix it :)

hirios commented 3 years ago

I was about to give up on using "mediaElement". Luckily I saw this thread so I was able to add the "FillAndExpand" attribute. Now it works fine. I didn't need to add storage access to the manifest, nor did I need to set the experimental flag.

davidbuckleyni commented 2 years ago

Same Issue in 2022 as this not been fixed yet? Even with this am getting nothing display though am using https://github.com/Tyrrrz/YoutubeExplode to covert to stream might be causing a dealy possilby will youtube stream support come in eventually

    <xct:MediaElement x:Name="mediaElement"
                      Grid.Row="0"
                      HeightRequest="500"
                      AutoPlay="True"
                      ShowsPlaybackControls="True"
                      VerticalOptions="FillAndExpand"
                        />
XamarinInfo commented 2 years ago

I only see an issue with no playback when the video source is a local resource on android.

The same issue I am facing here, no issue with the URL video but facing issue with the video that is added in resource. Issue with android version also,We dont have any issue with android 9 but isssue with version 10

XamarinInfo commented 2 years ago

The same issue I am facing here, no issue with the URL video but facing issue with the video that is added in the resource. Issue with Android version also, We don't have any issue with android 9 but issue with version 10

apovetkin commented 2 years ago

I have same issue.

Asked question here https://docs.microsoft.com/en-us/answers/questions/939040/mediaelement-is-not-working-for-xamarin-android.html

Any ideas why it's not show up?

ZivFarin commented 7 months ago

Had the same problem when media element was contained in a grid. This is what I found:

The grid had 2 rows. Media element is in the second row. Upper row had a label and a button.

  1. Containing grid had a RowDefinitions='Auto,*' Media element's VerticalOptions='FillAndExpand' Media element was not visible.
  2. Containing grid had a RowDefinitions='*,*' (or '*,6*' for that matter) Media element's VerticalOptions='FillAndExpand' Media element was visible.
  3. Containing grid had a RowDefinitions='*,*' (or '*,6*' for that matter) Media element's VerticalOptions='StartAndExpand' The video itself was not visible but the media element took some space (could see it's "BackgroundColor").

Adding this up to the discussion above leads me to believe that it is highly probable that the media element does not request for space(WidthRequest?\HightRequest) from it's parent after assessing the size of the video.