I am facing the problem while playing the local Video file (TestMediaPlayer.Video.Demo_Video.mp4) in Xamarin Platform.
I have created the Cross Platform Test application in Xamarin Platform. I would like to play local mp4 file from device Windows or Android. When I play the sample video from the web URL that work fine. But When I Play at local file system crash or not play that file. I have already set the property BuildAction = Embedded Resources for that Video file.
How to Play Local video (mp4) file in Xamarin platform
My Sample code as below :
MainPage.xml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:TestMediaPlayer"
xmlns:forms="clr-namespace:Plugin.MediaManager.Forms;assembly=Plugin.MediaManager.Forms"
x:Class="TestMediaPlayer.MainPage">
<StackLayout>
<forms:VideoView x:Name="VideoPlayer" HeightRequest="404" WidthRequest="404" />
</StackLayout>
</ContentPage>
Code Behind File MainPage.cs:
using Plugin.MediaManager;
using Plugin.MediaManager.Abstractions;
using Plugin.MediaManager.Abstractions.Enums;
using Plugin.MediaManager.Abstractions.Implementations;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace TestMediaPlayer
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
testVideo();
// CrossMediaManager.Current.Play("https://archive.org/download/BigBuckBunny_328/BigBuckBunny_512kb.mp4", MediaFileType.Video); // Online resources
}
private async void testVideo()
{
string fileFullName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalizedResources), "TestMediaPlayer/Video/Demo_Video.mp4");
await CrossMediaManager.Current.Play(new MediaFile("file://" + fileFullName, MediaFileType.Video, ResourceAvailability.Local));
}
}
}