记录和iOS上同时播放(PhoneGap的生成) [英] Record and play simultaneously on iOS (Phonegap build)

查看:372
本文介绍了记录和iOS上同时播放(PhoneGap的生成)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发iOS和使用的PhoneGap构建3.3.0版本的Andr​​oid应用程序。

I'm developing iOS and Android application using Phonegap Build version 3.3.0.

应用程序的主要焦点是录音与其他音频/音乐后台播放。

Main focus of application is audio recording with another audio / music playing in the background.

有关这两种情况下我使用PhoneGap的媒体API以正确的音频文件记录(IOS - 的* .wav / Android的 - * .AMR)和播放(iOS和Android - * .MP3)。

For both instances i'm using phonegap media api with correct audio files for recording (iOs - *.wav / Android - *.amr ) and playing (iOs and Android - *.mp3).

示例:

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

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

例如,在Android工作没有任何问题。录制声音和音乐的正常播放。但iOS中只有一个是可能的。无论是过去的调用,播放或录制。另一种与code返回错误 - 4

时的PhoneGap媒体API的iOS上的这种限制还是我失去了一些东西?

Is this limitation of Phonegap Media API on iOs or am I missing something?

推荐答案

在为了能够同时播放的媒体和录制音频,必须在AVAudioSession的类别属性设置为 AVAudioSessionCategoryPlayAndRecord 的。要做到这一点,你必须部署自定义的iOS插件,设置相应的值。

In order to be able to simultaneously play media and record audio, one must set the category property of the AVAudioSession to AVAudioSessionCategoryPlayAndRecord. To do so you must deploy a custom iOS plugin that sets the corresponding value.

在当时来讲,这个过程是因为在科尔多瓦媒体插件中的错误不是很简单。开始录制之前,插件设置AVAudioSession的类别的 AVAudioSessionCategoryRecord 的乱射。正因为如此,在开始录制,播放所需的介质后变得不可能,除非你明确地设置AVAudioSession类调用记录方法后,以播放和录制,。这清楚地影射,你只能发挥你的媒体, 录制开始之后。

At the time speaking, this process is not quite straightforward because of a bug in the Cordova Media Plugin. Before starting to record, the plugin sets the category of the AVAudioSession to AVAudioSessionCategoryRecord indiscriminately. Because of that, after starting to record, playing back the desired media becomes impossible, unless you explicitly set the AVAudioSession category to play-and-record, after calling the record method. This clearly insinuates that you can only play your media, after recording has started.

然而,这种解决方法可能无法接受在许多情况下,这可能需要媒体开始播放录制的声音了。因此,我已经申请有关的问题,你可能在这里找到一个bug报告:

However, this workaround may not be acceptable in many scenarios, which may require that media starts to play before sound is recorded. Thus, I have filed a bug report regarding the issue, which you may find here:

的iOS媒体插件:不能播放视频和音频记录同时

另外,我已经申请了固定和执行以下拉要求:

Plus, I have applied the fix and performed the following pull request:

检查avSession.category已经被设置为AVAudioSessionCategoryPlayAndRecord录制前

这真是一个小的修复(code字面上两条线),所以我相信它很快就会应用到主分支。

It's really a minor fix (literally two lines of code), thus I believe that it will be soon applied to the master branch.

这篇关于记录和iOS上同时播放(PhoneGap的生成)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆