在Ionic 3上录制和播放audio

我在iOS上有一个奇怪的问题。

我正在使用Ionic Native Media插件录制audio,并尝试使用HTML5 Web Audio API(WavesurferJS或HowlerJS)播放录音。 如果我尝试立即播放录音,录制audio后,audio将无法播放,但如果closures了应用程序,然后重新打开它,audio将播放正常。

HowlerJS投掷的错误是“audio解码错误”。 我的想法是Native Media插件没有完全释放该文件,因此没有给予HowlerJS读取audio数据的权限。

任何想法或方向表示赞赏。

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 */ 

使用cordova插件媒体:

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

离子文档有用的文章:

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