XamarinMediaManager icon indicating copy to clipboard operation
XamarinMediaManager copied to clipboard

Some of common video type unable to play

Open luiey opened this issue 5 years ago • 2 comments

🐛 Bug Report

Unable to play some of common video type.

Expected behavior

Common known video type should able to play

Reproduction steps

I have download multiple sample of video type and place it on my removable mass storage (USB Drive) and run my xamarin.forms on android device to get every file on my usb to be play on screen.

// Private declaration
private readonly List<string> ListVideoExtension = new List<string>() { ".WMV", ".MP4", ".AVI", ".MPEG", ".AVI", ".MPG", ".3GP", ".FLV", ".M4V", ".MKV", ".MOV", ".MTS", ".VOB", ".WEBM", ".OGV" };


//Methods
private int TransitionTime = 10000;
#region MEDIA PLAYER
private void DeclareMediaManagerHandler()
{
    try
    {
        CrossMediaManager.Current.MediaItemFailed += Current_MediaItemFailed;
        CrossMediaManager.Current.MediaItemFinished += Current_MediaItemFinished;
    }
    catch (Exception ex)
    {
        Console.WriteLine($"[{TAG}] Error declare media manager handler. " + ex);
    }
}
private async void PlayMediaFile()
{
	try
	{
		Indx = 0;
		while (true)
		{
			var files = ListMediaFile[Indx];
			MediaFileName = Path.GetFileName(files);
			IsVideoVisible = false;
			if (ListVideoExtension.FirstOrDefault(o => o.Contains(Path.GetExtension(files).ToUpper())) != null)
			{

				if (File.Exists(files))
				{
					IsVideoVisible = true;
					IsVideoBusy = true;
					MediaManager.CrossMediaManager.Current.Play(files);
					while (IsVideoBusy) { if (IsVideoBusy == false) break; }
					if (IsVideoProperFinish)
						goto SKIPFORVIDEO;
				}
				else
				{
					LabelVisible = true;
					LabelMessage = "Current video resource not exist on selected directory.";
					Console.WriteLine($"[{TAG}] Current video resource not exist on selected directory. Path: {files}");
				}
			}
			await Task.Delay(TransitionTime);
			SKIPFORVIDEO:
			Indx++;
			if (Indx == ListMediaFile.Count)
			{
				Indx = 0;
			}
		}
	}
	catch (Exception ex)
	{
		Console.WriteLine($"[{TAG}] Error on play file. " + ex);
		Toast("Error on play file. " + ex.Message, ToastStyle.Error, Plugin.Toast.Abstractions.ToastLength.Long);
	}
}
#endregion
#region MEDIA MANAGER EVENT
private void Current_MediaItemFinished(object sender, MediaManager.Media.MediaItemEventArgs e)
{
	IsVideoBusy = false;
	IsVideoProperFinish = true;
}
private void Current_MediaItemFailed(object sender, MediaManager.Media.MediaItemFailedEventArgs e)
{
	IsVideoBusy = false;
	IsVideoProperFinish = false;
	LabelMessage = "Unable to play video file";
	LabelVisible = true;
}
#endregion

As on my code, below are the result: ABLE TO PLAY ".MP4", ".MPEG", ".MPG", ".3GP", ".M4V", ".MKV", ".MOV", ".MTS", ".VOB", ".WEBM"

FAILED TO PLAY ".WMV", ".AVI", ".FLV", ".OGV"

Sample video download from here.

Configuration

Version: 1.x

Platform:

  • [ ] :iphone: iOS
  • [X] :robot: Android
  • [ ] :checkered_flag: WPF
  • [ ] :earth_americas: UWP
  • [ ] :apple: MacOS
  • [ ] :tv: tvOS
  • [X] :monkey: Xamarin.Forms

luiey avatar Dec 31 '19 09:12 luiey

Is this issue fixed? I am facing issue with .avi as well on Android

LukasThijs avatar Oct 29 '20 14:10 LukasThijs

you sure that MKV is supported? cuz i can't play MKV url's

mhrastegari avatar Apr 24 '21 17:04 mhrastegari