1

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
H_H
  • 126
  • 2
  • 9

1 Answers1

0

This issue in my knowledge would be occurring because of the video type that iPhone's have which in knowledge is MOV, but when you play that in Android it will not work as Android by default support it, you need a Video player like VLC for it to work. The best way of handling this issue if you ask me would be video conversion which you can do using AVAssetExportSession in Xamarin iOS.

What you do is something like this:

        var asset = AVAsset.FromUrl( NSUrl.FromFilename( sourceFilePath ) )

        AVAssetExportSession export = new AVAssetExportSession (asset, AVAssetExportSession.PresetLowQuality );

        export.OutputUrl = new NSUrl ( downloadFilePath );
        export.OutputFileType = AVFileType.Mpeg4;
        export.ShouldOptimizeForNetworkUse = true;

        export.ExportAsynchronously(  ( ) => 
        {
            System.Diagnostics.Debug.WriteLine( export.Error.LocalizedDescription );
        });

You can check this Xamarin Forums discussion for more details.

You can also check this StackOverflow question that deals with something similar MOV to Mp4 video conversion iPhone programmatically

FreakyAli
  • 13,349
  • 3
  • 23
  • 63
  • Thank you for answer.. we already did this step and also we try adding the vlc to android but we faced the green issue https://forums.xamarin.com/discussion/152443/using-vlc-player-in-xamarin-android-project – H_H Jul 10 '19 at 05:34
  • So you are converting from MOV to MP4? – FreakyAli Jul 10 '19 at 05:49
  • yes we are doing so .. to make it work we are converting on the server as well .. the encoding of the MP4 still not readable by the android devices even after the convert .. we need the conversion to be on the devices not on the server. – H_H Jul 10 '19 at 06:05
  • I do not personally think you need any more changes when you do the above on the server-side, you can obviously compress but convert at one place only – FreakyAli Jul 10 '19 at 06:06
  • any suggestions? – H_H Jul 11 '19 at 10:53