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);
有帮助吗?

解决方案

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.

其他提示

You are using the loosely typed NSDictionary-based API.

You could avoid these errors in the future if you use the other constructor that takes an AudioSettings parameter, which conveniently provides intellisense for you.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top