1

Hi I'm using following setting to record in swift

let audioFilename = getDocumentsDirectory().stringByAppendingPathComponent("recording.m4a")
let audioURL = NSURL(fileURLWithPath: audioFilename)

let settings = [
  AVFormatIDKey: Int(kAudioFormatMPEG4AAC),
  AVSampleRateKey: 44100.0,
  AVNumberOfChannelsKey: 2 as NSNumber,
  AVLinearPCMBitDepthKey: 16 as NSNumber,
  AVLinearPCMIsBigEndianKey: false as NSNumber,
  AVLinearPCMIsFloatKey: false as NSNumber,
  AVEncoderAudioQualityKey: AVAudioQuality.High.rawValue
]

but that m4a file not play on android

mediaPlayerAdd = MediaPlayer.create(AndroidPlayerActivity.this, R.raw.recording);
mediaPlayerAdd.prepare();
mediaPlayerAdd.start();

no error and not playing. How to play this file in android any conversion needed

NBoymanns
  • 686
  • 6
  • 16
sabeer
  • 603
  • 10
  • 28

1 Answers1

4

I had the same problems some months ago and I solved it changing the file extension from M4A to ACC. Android can play AAC format audio if it's encoded as MPEG-4 or 3GPP; instead AAC there is a raw MPEG-4 with audio stream encoded.

With this workaround I'm able to play local AAC files on my Android application.

  • Thanks @Michele its working Any idea if record android and play on ios – sabeer Dec 10 '15 at 10:28
  • Yes @sabeer you can follow this guide on Stack Overflow: [link](http://stackoverflow.com/questions/15871407/audio-format-for-ios-and-android). This solution works great for both platforms. –  Dec 10 '15 at 14:39