Search code examples
c#androidvisual-studio-2019uno-platformmediaplayerelement

UNO Platform: Droid Project - Media Player element will not play mp4 from project file


New to UNO Platform. Working on a test project and having trouble playing mp4 using MediaPlayerElement on Droid. MyVideo.mp4 is in Shared/Assets/Videos with Build Action = Content; and Copy to Output Directory = Do Not Copy. Have tried setting to embedded project; placing it under the Droid Assets/Raw/MyVideo.mp4 with a Build Action = AndroidResource. Tried adding permission to READ_EXTERNAL_STORAGE to the AndroidManifest.xml. Have tried several different versions of paths. Project is on Windows 10 PC using VS2019/UNO Platform being built to Samsung 2016 tablet. App loads, no errors, poster displays correctly, transport controls display, but the video won't play.

Here's the XAML.

<Grid>
    <MediaPlayerElement x:Name="mediaPlayer" 
                  HorizontalAlignment="Center" 
                  VerticalAlignment="Top" 
                  Stretch="Uniform" 
                  AutoPlay="True"
                  Source="ms-appx:///Assets/Videos/MyVideo.mp4"
                  PosterSource = "ms-appx:///Assets/Posters/MyPoster.jpg"
                  AreTransportControlsEnabled="True">
        <MediaPlayerElement.TransportControls>
            <MediaTransportControls IsCompact="True" RequestedTheme="Dark" />
        </MediaPlayerElement.TransportControls>
    </MediaPlayerElement>
</Grid>

The code behind is empty except for the this.InitializeComponent(); in the constructor.

Any help is greatly appreciated. Thank you.


Solution

  • I believe this answer would apply here: https://stackoverflow.com/a/60940283/3745725.

    You were on the right track by placing the mp4 file directly in the Android Assets folder rather than the Shared project. The Build Action of the mp4 within the Android project should be set to AndroidAsset. That should do the trick.

    Hopefully this helps! If not, let me know so we can continue to investigate.