0

Im building an application where Im using cordova media to record audio on both ios and android. I encode the audio to a base64 string and send it to a server (parse.com) and save it as a file. When I want to play it, I play the url from the file after I click on a button on the devices. When I record the audio as a wav file on ios I can play it on both ios and android. But when I record on android I can only play it back on android devices.

Im struggling to find a format which I can record on android and play it on ios. I have tried wav, mp3, mp4, aac and 3gp. I have tried amr as well, but then it looks like it download the file to the phone and that is not what I want to do.

Can someone please help, Im really lost here.

Thomas M. Tveten
  • 467
  • 1
  • 9
  • 22
  • When does the audio get Base64 decoded? – Dan S Mar 05 '14 at 00:04
  • I actually never decode it. I send it up as the base64 string, and are able to play it in my browser, or on my phone which Im still have some problems with (the ios part). I would like to record the audio file as a wav file on android as well, but when I do so it says audio/x-wav, which Im not able to play on the ios (just in the browser) – Thomas M. Tveten Mar 05 '14 at 00:10
  • Just to be clear, is the audio data embedded like [this](http://stackoverflow.com/questions/1207190/embedding-base64-images) question does for images? – Dan S Mar 05 '14 at 00:19
  • No, I get the url from parse.com (the server where I made a file from my base64) and make a new media object with this url. The url will typically look like this http://files.parse.com/e338afd3-87c0-45e0-9d6a-54e9b6988fc8/5b6a3c9b-ca12-4dc9-8f06-105bec8a2a95-sound.mpeg I don't know if that is the right way to go though.. – Thomas M. Tveten Mar 05 '14 at 00:22
  • This [multimedia programming article](https://developer.apple.com/library/ios/documentation/audiovideo/conceptual/multimediapg/usingaudio/usingaudio.html) from Apple suggests that a 3GPP stream should play inside an MPEG4 container file. – Dan S Mar 05 '14 at 00:32
  • I will take a look at it, and try the audio approach where I use the base64 and not the file url as you suggested – Thomas M. Tveten Mar 05 '14 at 00:45
  • Im trying the new Audio(base64) with ios but I get the error "the operation could not be completed". Any idea why this happen? – Thomas M. Tveten Mar 05 '14 at 01:05

1 Answers1

0

Here's what I used. It plays audio properly in iOS.

    recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
    recorder.setAudioSamplingRate(44100);
    recorder.setAudioEncodingBitRate(96000);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
dannyroa
  • 5,501
  • 6
  • 41
  • 59
  • But this is java code from android api correct? Im using cordova (javasript). But I could check if I can chenge the sampling and bitrate on the media object in cordova – Thomas M. Tveten Mar 05 '14 at 00:19
  • I changed the default settings now in the java file to what you suggested and added recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); I just got one question, what do I set as outputFile. In cordova, I need to write something like recording.mp3 or .wav. I therefore need to know that format the file will have when I record it as a MPEG_4 and AAC file. – Thomas M. Tveten Mar 05 '14 at 13:31