MediaElement is not working for Xamarin Android -10 while playing video from raw folder

XamarinInn 1 Reputation point
2022-02-17T04:15:31.303+00:00

Trying with MediaElement in Xamarin.

It is not working in android 10 when taking video from 'raw' folder. We are not facing this issue in Android 9. We are not facing this issue if we are giving a URL as a source.

demo project is added in the following link--> https://github.com/devcrux/Xamarin.Forms-Shapes

Steps followed. 1.Added ' Device.SetFlags(new[] { "Shapes_Experimental", "MediaElement_Experimental" });' in App class. 2.Added mp4 file in row folder 3.Build action is given as 'Android Resource' 4.MediaElement is added like

<MediaElement
x:Name="mediaElementBar"
Source="https://qdserversas1.eastus.cloudapp.azure.com:571/video/hospital.mp4"
ShowsPlaybackControls="False"
IsLooping="True" Aspect="AspectFill" AutoPlay="True"
SeekCompleted="mediaElementBar_SeekCompleted"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>

. Please help me to fix this issue.

Thanx in advance :)

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,334 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,711 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 74,081 Reputation points Microsoft Vendor
    2022-02-17T05:50:25.7+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    1. Please update your Xamarin.forms(5.0.0.2337) and Xamarin.essentials(1.7.1) nuget package to the latest.
    2. Then search Xamarin.CommunityToolkit nuget package in the Nuget package manager, install it
    3. Set the Android Target framework to the latest verion(My latest version is Android 12.0(S)) and Target Android Version to latest version((My latest version is Android 12.0(S)) )
    4. Add the pre-fix in the MainPage.xaml like following code. I run it, this video play normally in android 10 or 11. <?xml version="1.0" encoding="utf-8" ?>
      <ContentPage
      ...
      xmlns:local="http://xamarin.com/schemas/2020/toolkit"
                ...  
               >  
      
      ...
      <local:MediaElement Source="ms-appx:///yoga2.mp4" ShowsPlaybackControls="False"
      IsLooping="True" Aspect="AspectFill" AutoPlay="True"
      HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
      ...

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.