IOS видео не воспроизводится на Android - PullRequest
1 голос
/ 09 июля 2019

Мы создаем мобильное приложение для чата на xamarin native.у нас возникли проблемы с видео. Видео, отправленные из приложения IOS, невозможно воспроизвести на мультимедийном проигрывателе по умолчанию на устройствах Android из-за некоторых проблем с кодировкой.

Чтобы решить эту проблему, мы конвертируем видео науровень сервера, который на нем много обрабатывает.

Как можно установить этот процесс?Может быть, закодировать видео на устройстве перед его отправкой?

Заранее спасибо.

Мы используем это преобразованное из предложений, но оно не конвертируется, и средство выбора застревает на снимке видео:


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;
                            }
                        });
                    }

Вот что показывает в журнале:

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

1 Ответ

0 голосов
/ 09 июля 2019

Насколько мне известно, эта проблема возникает из-за типа видео, которое есть у iPhone, которое в знаниях называется MOV, но когда вы воспроизводите его в Android, оно не будет работать, поскольку Android по умолчанию поддерживает его, вам нужен видеоплеер, такой как VLC чтобы это работало. Если вы спросите меня, лучшим способом решения этой проблемы будет преобразование видео, которое вы можете сделать, используя AVAssetExportSession в Xamarin iOS.

То, что вы делаете, выглядит примерно так:

        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 );
        });

Вы можете проверить это Обсуждение Xamarin Forums для получения более подробной информации.

Вы также можете проверить этот вопрос StackOverflow, который имеет дело с чем-то похожим Преобразование видео MOV в Mp4 для iPhone программно

...