$cordovaNativeAudio



Cordova / PhoneGap 3.5 +本地音频播放,针对HTML5游戏和音频应用所需的最小延迟,复调和并发。



cordova plugin add https://github.com/SidneyS/cordova-plugin-nativeaudio.git


代码实例

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);
					  };
					
					});