We are building a mobile chatting app on xamarin native. we are having problem with videos videos that are sent from IOS application are not able to be played on the default media player of android devices due to some encoding issue.
to solve this problem we are converting the video on the level of the server which is taking a lots of processing on it.
What is the way to be able to establish this process to work out? maybe encode the video on the device before it is send?
Thanks in advance.
We Use this converted from the suggestions but its not converting and the picker is stuck on the video snapshot:
Picker = new UIImagePickerController()
{
SourceType = type,
MediaTypes = UIImagePickerController.AvailableMediaTypes(type),
VideoExportPreset = AVAssetExportSessionPreset.Passthrough.GetConstant().ToString(),
VideoQuality = UIImagePickerControllerQualityType.Medium,
//AllowsImageEditing = false,
VideoMaximumDuration = 120f
};
var srcUrl = e.Info[UIImagePickerController.MediaURL] as NSUrl;
AVUrlAsset avAsset = new AVUrlAsset(srcUrl, new NSDictionary());
string[] compatiblePresets = AVAssetExportSession.ExportPresetsCompatibleWithAsset(avAsset);
if (compatiblePresets.Contains("AVAssetExportPresetLowQuality"))
{
AVAssetExportSession exportSession = new AVAssetExportSession(avAsset, AVAssetExportSessionPreset.Passthrough);
//var destFile = fileService.MoveFileToMyDocument(srcUrl.Path, ChatMessageType.Video);
string destFile = System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid().ToString() + ".mp4");
exportSession.OutputUrl = new NSUrl(destFile);
exportSession.OutputFileType = AVFileType.Mpeg4;
exportSession.ShouldOptimizeForNetworkUse = true;
exportSession.ExportAsynchronously(() =>
{
switch (exportSession.Status)
{
case AVAssetExportSessionStatus.Failed:
//If this fails, it might be because the temorary
//files weren't cleaned and this isn't overwriting
//the temporary filename
Console.WriteLine(@"Export failed: " + exportSession.Error.LocalizedDescription);
//Perform any failed logic
Picker.DismissViewControllerAsync(true);
break;
case AVAssetExportSessionStatus.Cancelled:
Console.WriteLine(@"Export canceled");
//Perform any cancel logic
Picker.DismissViewControllerAsync(true);
break;
default:
//This should have been a success
//File should be saved at filePath
//Upload file from here
var url = fileService.GetFullPath(exportSession.OutputUrl.ToString());
SendMedia(url, ChatMessageType.Video);
break;
}
});
}
This what shows in the log:
System.NotSupportedException: Specified method is not supported.
at Mono.Debugger.Soft.VirtualMachine.EncodeValue (Mono.Debugger.Soft.Value v, System.Collections.Generic.List`1[T] duplicates) [0x000df] in /Users/vsts/agent/2.153.2/work/1/s/monodevelop/main/external/debugger-libs/Mono.Debugger.Soft/Mono.Debugger.Soft/VirtualMachine.cs:686
at Mono.Debugger.Soft.VirtualMachine.EncodeValues (System.Collections.Generic.IList`1[T] values, System.Collections.Generic.List`1[T] duplicates) [0x00010] in /Users/vsts/agent/2.153.2/work/1/s/monodevelop/main/external/debugger-libs/Mono.Debugger.Soft/Mono.Debugger.Soft/VirtualMachine.cs:693
at Mono.Debugger.Soft.ObjectMirror.BeginInvokeMethod (Mono.Debugger.Soft.VirtualMachine vm, Mono.Debugger.Soft.ThreadMirror thread, Mono.Debugger.Soft.MethodMirror method, Mono.Debugger.Soft.Value this_obj, System.Collections.Generic.IList`1[T] arguments, Mono.Debugger.Soft.InvokeOptions options, System.AsyncCallback callback, System.Object state) [0x00094] in /Users/vsts/agent/2.153.2/work/1/s/monodevelop/main/external/debugger-libs/Mono.Debugger.Soft/Mono.Debugger.Soft/ObjectMirror.cs:311
at Mono.Debugger.Soft.ObjectMirror.InvokeMethod (Mono.Debugger.Soft.VirtualMachine vm, Mono.Debugger.Soft.ThreadMirror thread, Mono.Debugger.Soft.MethodMirror method, Mono.Debugger.Soft.Value this_obj, System.Collections.Generic.IList`1[T] arguments, Mono.Debugger.Soft.InvokeOptions options) [0x00000] in /Users/vsts/agent/2.153.2/work/1/s/monodevelop/main/external/debugger-libs/Mono.Debugger.Soft/Mono.Debugger.Soft/ObjectMirror.cs:387
at Mono.Debugger.Soft.TypeMirror.NewInstance (Mono.Debugger.Soft.ThreadMirror thread, Mono.Debugger.Soft.MethodMirror method, System.Collections.Generic.IList`1[T] arguments, Mono.Debugger.Soft.InvokeOptions options) [0x00026] in /Users/vsts/agent/2.153.2/work/1/s/monodevelop/main/external/debugger-libs/Mono.Debugger.Soft/Mono.Debugger.Soft/TypeMirror.cs:837
at Mono.Debugger.Soft.TypeMirror.NewInstance (Mono.Debugger.Soft.ThreadMirror thread, Mono.Debugger.Soft.MethodMirror method, System.Collections.Generic.IList`1[T] arguments) [0x00000] in /Users/vsts/agent/2.153.2/work/1/s/monodevelop/main/external/debugger-libs/Mono.Debugger.Soft/Mono.Debugger.Soft/TypeMirror.cs:827
at Mono.Debugging.Soft.SoftDebuggerAdaptor.CreateValue (Mono.Debugging.Evaluation.EvaluationContext ctx, System.Object type, System.Object[] argValues) [0x0019e] in /Users/vsts/agent/2.153.2/work/1/s/monodevelop/main/external/debugger-libs/Mono.Debugging.Soft/SoftDebuggerAdaptor.cs:524
at Mono.Debugging.Evaluation.NRefactoryExpressionEvaluatorVisitor.VisitObjectCreateExpression (ICSharpCode.NRefactory.CSharp.ObjectCreateExpression objectCreateExpression) [0x0005e] in /Users/vsts/agent/2.153.2/work/1/s/monodevelop/main/external/debugger-libs/Mono.Debugging/Mono.Debugging.Evaluation/NRefactoryExpressionEvaluatorVisitor.cs:1081
at ICSharpCode.NRefactory.CSharp.ObjectCreateExpression.AcceptVisitor[T] (ICSharpCode.NRefactory.CSharp.IAstVisitor`1[S] visitor) [0x00000] in /Users/vsts/agent/2.153.2/work/1/s/monodevelop/main/external/nrefactory/ICSharpCode.NRefactory.CSharp/Ast/Expressions/ObjectCreateExpression.cs:90
at Mono.Debugging.Evaluation.NRefactoryExpressionEvaluator.Evaluate (Mono.Debugging.Evaluation.EvaluationContext ctx, System.String expression, System.Object expectedType) [0x00157] in /Users/vsts/agent/2.153.2/work/1/s/monodevelop/main/external/debugger-libs/Mono.Debugging/Mono.Debugging.Evaluation/NRefactoryExpressionEvaluator.cs:82
at Mono.Debugging.Evaluation.ExpressionEvaluator.Evaluate (Mono.Debugging.Evaluation.EvaluationContext ctx, System.String exp) [0x00000] in /Users/vsts/agent/2.153.2/work/1/s/monodevelop/main/external/debugger-libs/Mono.Debugging/Mono.Debugging.Evaluation/ExpressionEvaluator.cs:43
at Mono.Debugging.Evaluation.ObjectValueAdaptor.GetExpressionValue (Mono.Debugging.Evaluation.EvaluationContext ctx, System.String exp) [0x00000] in /Users/vsts/agent/2.153.2/work/1/s/monodevelop/main/external/debugger-libs/Mono.Debugging/Mono.Debugging.Evaluation/ObjectValueAdaptor.cs:1416 Thread started: #13
Thread finished: <Thread Pool> #6
2019-07-10 10:14:25.501 MyApp[319:18031] Export failed: The operation could not be completed