Record and play simultaneously on iOS (Phonegap build)

I am developing an iOS and Android application using Phonegap Build version 3.3.0.

The main focus of the application is audio recording with other sound / music playback in the background.

For both instances, I use phonegap media api with the correct audio files for recording (iOs - * .wav / Android - * .amr) and games (iOs and Android - * .mp3).

Example:

var audioRec = new Media(audioRecSrc, onSuccess, onError);
audioRec.startRecord();

var audioPlay = new Media(audioPlaySrc, onSuccess, onError);
audioPlay.play();

The example runs on Android without any problems. Sound is recorded and music is played normally. But on iOS, only one thing is possible. Whatever is called last, play or record. Another returns an error with code - 4 .

Is this a limitation of the Phonegap Media API for iOS, or am I missing something?

+4
source share
2 answers

To play media and record audio at the same time, you must set the property of the AVAudioSession category to AVAudioSessionCategoryPlayAndRecord. To do this, you must deploy the custom iOS plugin, which sets the appropriate value.

, , - - Cordova. AVAudioSession AVAudioSessionCategoryRecord . - , AVAudioSession , . , , .

, , , . , , :

iOS Media:

, :

, ​​ avSession.category "AVAudioSessionCategoryPlayAndRecord"

( ), , .

+3

, , . Cordova Media API, iOS , , WAV . , ( , , ), script , , :

var audioRecSrc = "myrecording.wav";
var audioPlaySrc = "audiotoplay.mp3"

// Wait for PhoneGap to load
document.addEventListener("deviceready", onDeviceReady, false);

// PhoneGap is ready
function onDeviceReady() {
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}

function gotFS(fileSystem) {
    fileSystem.root.getFile(audioRecSrc, {create: true, exclusive: false}, gotFileEntry, fail);
}

function gotFileEntry(fileEntry) {
    var audioRec = new Media(audioRecSrc, onSuccess, onError);
    audioRec.startRecord();

    var audioPlay = new Media(audioPlaySrc, onSuccess, onError);
    audioPlay.play();
}

function fail(error) {
    console.log("error : " + error.code);
}

API Cordova, . , API (, , )


iOS. Mobile Safari (PhoneGap UIWebView iPhone SDK):

-

, iOS, . , - iOS. . . . " " (. 41)

, , , . StarComposer, iPhone , PhoneGap. PhoneGap Cordova, JavaScript, . , , HTML5 iOS. , , 23:

https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Using_HTML5_Audio_Video.pdf

0

Source: https://habr.com/ru/post/1537718/


All Articles