简体   繁体   English

在Ionic 3上录制和播放音频

[英]Recording and playing back audio on Ionic 3

I am having a weird issue on iOS. 我在iOS上遇到了一个奇怪的问题。

I am using the Ionic Native Media plugin to record audio and trying to play the recording back using the HTML5 Web Audio API (WavesurferJS or HowlerJS). 我正在使用Ionic Native Media插件录制音频,并尝试使用HTML5 Web音频API(WavesurferJS或HowlerJS)播放录音。 After I record the audio if I try to play the recording back immediately the audio will not play, but if I close the app and then re-open it, the audio will play fine. 录制音频后,如果尝试立即回放录音,则音频不会播放,但是如果我关闭该应用程序然后重新打开,则音频会正常播放。

The error that HowlerJS is throwing is "error decoding the audio." HowlerJS抛出的错误是“解码音频时出错”。 My thoughts are the Native Media plugin has not fully released the file, thus not giving permissions to HowlerJS to read the audio data. 我的想法是,Native Media插件尚未完全释放文件,因此未授予HowlerJS读取音频数据的权限。

Any thoughts or direction is appreciated. 任何想法或方向表示赞赏。

https://github.com/ionic-team/ionic-native/blob/master/src/%40ionic-native/plugins/media/index.ts - mentions stuff in comments.. https://github.com/ionic-team/ionic-native/blob/master/src/%40ionic-native/plugins/media/index.ts-在评论中提及内容。

 * Some hints if you are using iOS and recording doesn't work:
 * 1.) Try to use a absolute file path but remove beginning "file://".
 * Then it looks like: `/var/mobile/Containers/Data/Application/AF438B8B-7724-4FBB-8E69-083463224FC4/tmp/my_file.m4a`
 * Example: `this.media.create(this.file.tempDirectory.replace(/^file:\/\//, '') + 'my_file.m4a')`
 * 2.) If that's not working, too, create the file before using.
 * Example:
 * ```typescript
 * import { Media, MediaObject } from '@ionic-native/media';
 * import { File } from '@ionic-native/file';
 *
 * ...
 *
 * constructor(private media: Media, private file: File) { }
 *
 * ...
 *
 * this.file.createFile(this.file.tempDirectory, 'my_file.m4a', true).then(() => {
 *   let file = this.media.create(this.file.tempDirectory.replace(/^file:\/\//, '') + 'my_file.m4a');
 *   file.startRecord();
 *   window.setTimeout(() => file.stopRecord(), 10000);
 * });
 * ```
 *
 * You can find the reasons here: https://github.com/ionic-team/ionic-native/issues/1452#issuecomment-299605906
 * @classes
 * MediaObject
 * @interfaces
 * MediaError
 */

Use Cordova Plugin Media : 使用Cordova插件媒体:

$ ionic cordova plugin add cordova-plugin-media
$ npm install --save @ionic-native/media

Useful article from ionic doc : ionic doc的有用文章:

https://ionicframework.com/docs/native/media/ https://ionicframework.com/docs/native/media/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 HTML5音频-录制可以保存文件,但是通过音频控件播放时没有声音 - HTML5 audio - recording saves file OK, but no sound when playing back through audio control 播放离子的外部音频 - Playing external audio in ionic 实时录制和播放音频作为缓冲区 - Real time recording and playing audio as buffer 录制并稍后在Firefox中播放DOM更改? - Recording and later playing back DOM changes in Firefox? 录制后停止jRecorder播放 - Stop jRecorder playing back after recording 离子3:播放Icecast / Shoutcast音频流 - Ionic 3: playing an Icecast/Shoutcast audio stream 使用javascript usermedia和web audio api在浏览器上以恒定的延迟播放和录制 - Playing and Recording with a constant latency on browser with javascript usermedia and web audio api 播放通过网络音频 API 录制的音频的爆裂声和爆裂声 - Crackling and popping playing back audio recorded through web audio API WebRTC:获取mediaStream *的音频级别,而不播放音频 - WebRTC: Get audio level of a mediaStream *without* playing back the audio 在其他地方播放Android Cordova中录制的3gp音频 - Playing back 3gp audio recorded in Android Cordova elsewhere
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM