1. 程式人生 > >ionic新增cordova外掛-NativeAudio

ionic新增cordova外掛-NativeAudio

NativeAudio
Cordova / PhoneGap 3.5 +本地音訊播放,針對HTML5遊戲和音訊應用所需的最小延遲,復調和併發。

cordova plugin add cordova-plugin-nativeaudio

Examples

module.controller('MyCtrl', function($scope, $cordovaNativeAudio, $timeout) {

  $cordovaNativeAudio
    .preloadSimple('click', 'audio/click.mp3')
    .then(function (msg)
{
console.log(msg); }, function (error) { alert(error); }); $cordovaNativeAudio .preloadComplex('music', 'audio/music.mp3', 1, 1) .then(function (msg) { console.log(msg); }, function (error) { console.error(error); }); $scope.play = function () {
$cordovaNativeAudio.play('click'); $cordovaNativeAudio.loop('music'); // stop 'music' loop and unload $timeout(function () { $cordovaNativeAudio.stop('music'); $cordovaNativeAudio.unload('click'); $cordovaNativeAudio.unload('music'); }, 1000 * 60); }; });