Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] MediaElement not showing up #400

Open
Mikilll94 opened this issue Feb 29, 2020 · 14 comments
Open

[Bug] MediaElement not showing up #400

Mikilll94 opened this issue Feb 29, 2020 · 14 comments
Labels
a/MediaElement bug Something isn't working. Breaky break. p/android This issue impacts Android

Comments

@Mikilll94
Copy link

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
@jsuarezruiz
Copy link
Collaborator

jsuarezruiz commented Mar 2, 2020

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
Copy link
Author

@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
Copy link

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

@Zangl
Copy link

Zangl commented Apr 21, 2020

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

@legyas
Copy link

legyas commented Jul 16, 2020

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
Copy link

Gogsi commented Jul 27, 2020

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
Copy link
Contributor

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

@jsuarezruiz jsuarezruiz transferred this issue from xamarin/Xamarin.Forms Oct 9, 2020
@jsuarezruiz jsuarezruiz added this to To Do in MediaElement Oct 9, 2020
@jfversluis
Copy link
Member

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 jfversluis added bug Something isn't working. Breaky break. p/android This issue impacts Android labels Jan 19, 2021
@hirios
Copy link

hirios commented Jun 27, 2021

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/MediaElement bug Something isn't working. Breaky break. p/android This issue impacts Android
Projects
Development

No branches or pull requests