XamarinCommunityToolkit icon indicating copy to clipboard operation
XamarinCommunityToolkit copied to clipboard

[Bug] MediaElement not showing up

Open Mikilll94 opened this issue 5 years ago • 14 comments

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

  • Version with issue: 4.5.0.356
  • IDE: 16.4.5
  • Platform Target Frameworks:
    • Android: 10

Mikilll94 avatar Feb 29 '20 20:02 Mikilll94

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

jsuarezruiz avatar Mar 02 '20 12:03 jsuarezruiz

@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.

Mikilll94 avatar Mar 02 '20 20:03 Mikilll94

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

JesperMLC avatar Mar 11 '20 15:03 JesperMLC

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

Zangl avatar Apr 21 '20 10:04 Zangl

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

legyas avatar Jul 16 '20 14:07 legyas

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;
            });

Gogsi avatar Jul 27 '20 11:07 Gogsi

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

thisisthekap avatar Sep 03 '20 09:09 thisisthekap

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

  • It seems to work if you use FillAndExpand
  • Specify a width- or heightrequest
  • Do the little scale trick

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

jfversluis avatar Jan 19 '21 19:01 jfversluis

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.

hirios avatar Jun 27 '21 22:06 hirios

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"
                        />

davidbuckleyni avatar Jan 16 '22 23:01 davidbuckleyni

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 avatar Feb 16 '22 06:02 XamarinInfo

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

XamarinInfo avatar Feb 16 '22 06:02 XamarinInfo

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?

apovetkin avatar Jul 23 '22 14:07 apovetkin

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.

ZivFarin avatar Jan 24 '24 09:01 ZivFarin