Search code examples
xamarin.iosavassetwriter

Monotouch - Error setting AVAssetWriterInput - unrecognized selector sent to instance


When I try to set the audio configuration writer input I'm getting an error:

-[__NSCFNumber length]: unrecognized selector sent to instance 0xbcdab0

My code:

        NSObject[] values = new NSObject[]
        {    
            NSNumber.FromFloat(44100.0f),
            NSNumber.FromInt32((int)MonoTouch.AudioToolbox.AudioFormatType.MPEG4AAC),
            NSNumber.FromInt32(2),
            NSNumber.FromInt32((int)AVAudioQuality.Medium)
        };
        //Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary
        NSObject[] keys = new NSObject[]
        {
            AVAudioSettings.AVSampleRateKey,
            AVAudioSettings.AVFormatIDKey,
            AVAudioSettings.AVNumberOfChannelsKey,
            AVAudioSettings.AVChannelLayoutKey
        };          
        //Set Settings with the Values and Keys to create the NSDictionary
        NSDictionary audiosettings = NSDictionary.FromObjectsAndKeys (values, keys);

        writeraudioInput = new AVAssetWriterInput (AVMediaType.Audio, audiosettings);

Solution

  • Seems like you're setting key to AVChannelLayoutKey and value to type of AVAudioQuality. They're no corresponding to each other. AVChannelLayoutKey's value should contant struct of AudioChannelLayout.

    Comment both last key and last values. Or fill and pass AudioChannelLayout structure.