一、音频播放
参考文档:https://ionicframework.com/docs/native/native-audio/
1、首先安装插件
ionic cordova plugin add cordova-plugin-nativeaudio npm install --save @ionic-native/native-audio
2、之后在appmodule里面配置
3、页面中引用
4、常用功能代码:
this.nativeAudio.preloadSimple('uniqueId1', 'path/to/file.mp3').then(onSuccess, onError); this.nativeAudio.preloadComplex('uniqueId2', 'path/to/file2.mp3', 1, 1, 0).then(onSuccess, onError); this.nativeAudio.play('uniqueId1').then(onSuccess, onError); // can optionally pass a callback to be called when the file is done playing this.nativeAudio.play('uniqueId1', () => console.log('uniqueId1 is done playing')); this.nativeAudio.loop('uniqueId2').then(onSuccess, onError); this.nativeAudio.setVolumeForComplexAsset('uniqueId2', 0.6).then(onSuccess,onError); this.nativeAudio.stop('uniqueId1').then(onSuccess,onError); this.nativeAudio.unload('uniqueId1').then(onSuccess,onError);
5、功能参数说明
preloadSimple(id, assetPath)将音频文件加载到内存中。针对短片段/单张照片(最多五秒钟)进行了优化。无法停止/循环播放。
ID string 音频文件的唯一ID
assetPath string 音频资产的相对路径或绝对URL(包括http://)。
play1(){ this.nativeAudio.preloadSimple('001', 'http://vip.chinayabisi.com/chinayabisi/xuanjiao/20180709/005.mp3').then(function(msg){ }, function(msg){ console.log( 'error: ' + msg ); }); }