如果您想在 Ionic-2 / Angular-2 移动应用程序中运行声音。
在此处遵循Ionic 2指南
安装:
ionic plugin add --save cordova-plugin-nativeaudio
npm install --save @ionic-native/native-audio
用法:
import { NativeAudio } from '@ionic-native/native-audio';
constructor(private nativeAudio: NativeAudio) { }
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'));
来源 1:https://stackoverflow.com/a/43917441/6786941