ChrisPfeiffer / Video_Recording

Proof of concept for recording and playing back video with Xamarin in iOS using AVFoundation.
3 stars 3 forks source link

StartRecordingToOutputFile delegate won't compile #1

Open quinnhoener opened 9 years ago

quinnhoener commented 9 years ago

In your code there's this line:

AVCaptureFileOutputRecordingDelegate avDel= new AVCaptureFileOutputRecordingDelegate ();

This throws compiler errors saying:

"Cannot create instance of the abstract class or interface 'AVFoundation.AVCaptureFileOutputRecordingDelegate'"

What is this delegate supposed to be?

ChrisPfeiffer commented 9 years ago

Hello @quinnhoener sorry for the delay. You need to create a class that inherits from AVCaptureFileOutputRecordingDelegate and instantiate that and pass it in instead.

Here is my example:

    public class recordingDelegate:AVCaptureFileOutputRecordingDelegate
    {

        //make it take a view controller so that we can pass in the view controller and call functions accessing the active view controller's properties

        public videoController activeViewController { get; set;}

        public override void FinishedRecording
        (
            AVCaptureFileOutput captureOutput,
            NSUrl outputFileUrl,
            NSObject[] connections,
            NSError nsError
        )
        {
            activeViewController.doneRecording ();

            if (nsError != null && nsError.LocalizedDescription != "Recording Stopped") {

                UIAlertView recordingFailedAlert = new UIAlertView("Recording Failed", "Sorry! The recording seems to have failed. Please try again!",null,"OK",null);
                recordingFailedAlert.Show();

            }

        }
    }

This is also better because then you can handle what to do when you're done recording regardless of how the recording is ended (button pushed, timeout etc...)

Hope this helps. I will update the sample soon!