Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-12542

can’t record to a “wav” file on IOS media plugin

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 3.5.0
    • Fix Version/s: None
    • Component/s: cordova-plugin-media
    • Labels:
    • Environment:

      9.x Simulator , IOS 8.x device (iPod touch)

      Description

      I get “Failed to initialize AVAudioRecorder: (null)” in the error callback of the startRecordingAudio() exec API.
      I see that the AVAudioPlayer settings in CDVAudio.m are

      NSDictionary *audioSettings = @{AVFormatIDKey: @(kAudioFormatMPEG4AAC),
                                                  AVSampleRateKey: @(44100),
                                                  AVNumberOfChannelsKey: @(1),
                                                  AVEncoderAudioQualityKey: @(AVAudioQualityMedium)
                                                  };
      

      This is IMHO the reason it doesn’t work. Either one uses the .m4a extension with kAudioFormatMPEG4AAC or
      .wav with the kAudioFormatLinearPCM key (the IOS docs are very unclear about which file extensions are actually supported)

      The plugin enforces “wav” but the settings enforce the MPEG4AAC encoder.
      Using the attached simple patch and using .m4a at the JS side solves the problem and records on my iPod touch IOS 8.x.

      I stumbled also across https://github.com/remoorejr/cordova-plugin-media-with-compression where the exchange wav->m4a is done too.

      Strangely I can’t find much problems reported on stackoverflow, but this one seems to cover it
      http://stackoverflow.com/questions/12244111/failed-to-initialize-avaudiorecorder-null
      The last poster seem to indicate that the problem sneaked in in IOS 8 (previously it was probably possible to record to a .wav file but with AAC content).

      Looking at the recordAudio() test for the plugin in tests/tests.js I can’t see that potential errors are actually causing the test to fail: they are just logged with console.log , so this may explain why the problem has not been detected by the tests.

        Attachments

        1. cdvsound.diff
          1.0 kB
          Leo Schubert

          Issue Links

            Activity

              People

              • Assignee:
                filmaj Filip Maj
                Reporter:
                leopatras Leo Schubert
              • Votes:
                3 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: