2016-12-01 2 views
0

Ich versuche eine Videoaufnahme mit AVFoundation zu erstellen, wo ich dieses Projekt als Standardprojekt verwende. https://github.com/ThatCSharpGuy/Forms-FullCameraPageAVCaptureFileOutputRecordingDelegate Kompilierfehler beim Versuch, Videoaufnahme in Xamarin Forms zu implementieren iOS mit AVFoundation

Jetzt versuche ich eine Start/Stop-Aufnahme-Funktion mit AVFoundation zu bauen, aber ich bleibe stecken, weil ich Probleme beim Erstellen einer neuen Instanz mit AVCaptureFileOutputRecordingDelegate habe. Das Projekt kann nicht ausgeführt werden, weil die folgende Fehlermeldung angezeigt wird: Cannot create an instance of the abstract class or interface "AVFoundation.AVCaptureFileOutputRecordingDelegate".

Ich fand einen Beitrag, der das gleiche Problem durchläuft https://forums.xamarin.com/discussion/33925/avcapturefileoutputrecordingdelegate-compile-error, aber eine Lösung wurde dort nicht gefunden.

Unten können Sie meinen Code sehen, wo ich jeden Schritt des Weges kommentiert habe.

Boolean weAreRecording; 

public override async void ViewDidLoad() 
    { 
     base.ViewDidLoad(); 
     SetupLiveCameraStream(); 
     SetupEventHandlers(); 
     weAreRecording = false; 
    } 

Inside my SetupLiveCameraStream i fügen zusätzlich (das Projekt ich den Rest des Codes innerhalb dieser Funktion verknüpft hat):

Console.WriteLine("Configuring output"); 
output = new AVCaptureMovieFileOutput(); 

long totalSeconds = 10000; 
Int32 preferredTimeScale = 30; 
CMTime maxDuration = new CMTime(totalSeconds, preferredTimeScale); 
output.MinFreeDiskSpaceLimit = 1024 * 1024; 
output.MaxRecordedDuration = maxDuration; 

    if (captureSession.CanAddOutput(output)) 
    { 
     captureSession.AddOutput(output); 
    } 

    captureSession.SessionPreset = AVCaptureSession.PresetMedium; 

... und auch:

var mic = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Audio); 
var micInput = AVCaptureDeviceInput.FromDevice(mic); 
captureSession.AddInput(micInput); 

Dann Ich habe die Event-Handler eingerichtet.

Dies ist meine Start/Stop-Aufnahme-Funktion unterhalb, wo der Kompilierfehler auftritt. Ich habe Probleme ein new AVCaptureFileOutputRecordingDelegate zu schaffen, wie ich oben mit der Fehlernachricht erwähnt Cannot create an instance of the abstract class or interface "AVFoundation.AVCaptureFileOutputRecordingDelegate", ich habe im Code kommentiert, wo Sie diese finden können:

AVCaptureMovieFileOutput output; 

    private void startStopPushed (object sender, EventArgs ea) 
    { 

     if (!weAreRecording) 
     { 
      System.Diagnostics.Debug.WriteLine("start recording"); 
      var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); 
      var library = System.IO.Path.Combine(documents, "..", "Library"); 
      var urlpath = System.IO.Path.Combine(library, "sweetMovieFilm.mov"); 

      NSUrl url = new NSUrl(urlpath, false); 

      NSFileManager manager = new NSFileManager(); 
      NSError error = new NSError(); 

      if (manager.FileExists(urlpath)) 
      { 
       Console.WriteLine("Deleting File"); 
       manager.Remove(urlpath, out error); 
       Console.WriteLine("Deleted File"); 
      } 



      AVCaptureFileOutputRecordingDelegate avDel= new AVCaptureFileOutputRecordingDelegate(); //Error message here: Cannot create an instance of the abstract class or interface `AVFoundation.AVCaptureFileOutputRecordingDelegate` 
      output.StartRecordingToOutputFile(url, avDel); 
      Console.WriteLine(urlpath); 
      weAreRecording = true; 

     } 

     //we were already recording. Stop recording 
     else { 

      output.StopRecording(); 

      System.Diagnostics.Debug.WriteLine("stopped recording"); 

      weAreRecording = false; 


     } 
    } 

Also meine Frage ist, wie kann ich dieses AVCaptureFileOutputRecordingDelegate Problem zu lösen?

Antwort

2

das ist, weil AVCaptureFileOutputRecordingDelegat abstrakte Funktion FinishedRecording hat. Sie können keine Instanz einer Klasse mit einem Abstract erstellen. Sie müssen eine Unterklasse von AVCaptureFileOutputRecordingDelegat erstellen und abstrakte Methoden implementieren, bevor Sie sie verwenden.

erstellen Unterklasse wie folgt aus:

public class myAvCaptureFileOutPutRecordingDelegate : AVCaptureFileOutputRecordingDelegat 
    { 
     public override void FinishedRecording(AVCaptureFileOutput captureOutput, Foundation.NSUrl outputFileUrl, Foundation.NSObject[] connections, Foundation.NSError error) 
     { 
      //You can use captureOutput and outputFileUrl here.. 
      //throw new NotImplementedException(); 
     } 


    } 

jetzt Instanz dieser Klasse erstellen:

AVCaptureFileOutputRecordingDelegate avDel= new myAvCaptureFileOutPutRecordingDelegate(); 
+0

Vielen Dank. Heute etwas Neues gelernt. Schätze es sehr – Martman