added support for external audio handler
diff --git a/player/index.html b/player/index.html
index ba64070..60c2f38 100644
--- a/player/index.html
+++ b/player/index.html
@@ -195,6 +195,7 @@
}
},
path: 'exports/render/data.json',
+ audioFactory: createAudio,
};
// lottie.setQuality('low');
// anim.setSpeed(0.5)
@@ -208,6 +209,12 @@
console.log(error)
})
+ function createAudio(assetPath) {
+ return new Howl({
+ src: [assetPath]
+ })
+ }
+
</script>
</body>
diff --git a/player/js/animation/AnimationItem.js b/player/js/animation/AnimationItem.js
index be21b3a..f487477 100644
--- a/player/js/animation/AnimationItem.js
+++ b/player/js/animation/AnimationItem.js
@@ -68,6 +68,9 @@
this.autoloadSegments = params.hasOwnProperty('autoloadSegments') ? params.autoloadSegments : true;
this.assetsPath = params.assetsPath;
this.initialSegment = params.initialSegment;
+ if (params.audioFactory) {
+ this.audioController.setAudioFactory(params.audioFactory);
+ }
if (params.animationData) {
this.configAnimation(params.animationData);
} else if(params.path){
diff --git a/player/js/elements/AudioElement.js b/player/js/elements/AudioElement.js
index ac8a59b..0ff7d48 100644
--- a/player/js/elements/AudioElement.js
+++ b/player/js/elements/AudioElement.js
@@ -6,9 +6,7 @@
this._isPlaying = false;
this._canPlay = false;
var assetPath = this.globalData.getAssetsPath(this.assetData);
- this.audio = new Howl({
- src: [assetPath]
- })
+ this.audio = this.globalData.audioController.createAudio(assetPath)
this._currentTime = 0;
this.globalData.audioController.addAudio(this);
this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate,this) : {_placeholder:true};
@@ -29,9 +27,9 @@
AudioElement.prototype.renderFrame = function() {
if (this.isInRange && this._canPlay) {
- if ((!this._isPlaying)) {
- this.audio.play()
- this.audio.seek(this._currentTime / this.globalData.frameRate)
+ if (!this._isPlaying) {
+ this.audio.play();
+ this.audio.seek(this._currentTime / this.globalData.frameRate);
this._isPlaying = true;
} else if (!this.audio.playing()
|| Math.abs(this._currentTime / this.globalData.frameRate - this.audio.seek()) > 0.1
diff --git a/player/js/utils/audio/AudioController.js b/player/js/utils/audio/AudioController.js
index 72517d2..e436fc1 100644
--- a/player/js/utils/audio/AudioController.js
+++ b/player/js/utils/audio/AudioController.js
@@ -1,7 +1,8 @@
var audioControllerFactory = (function() {
- function AudioController() {
+ function AudioController(audioFactory) {
this.audios = [];
+ this.audioFactory = audioFactory;
}
AudioController.prototype = {
@@ -25,6 +26,26 @@
for(i = 0; i < len; i += 1) {
this.audios[i].setRate(rateValue)
}
+ },
+ createAudio: function(assetPath) {
+ if (this.audioFactory) {
+ return this.audioFactory(assetPath);
+ } else if (Howl) {
+ return new Howl({
+ src: [assetPath]
+ })
+ } else {
+ return {
+ isPlaying: false,
+ play: function(){this.isPlaying = true},
+ seek: function(){this.isPlaying = false},
+ playing: function(){},
+ rate: function(){},
+ }
+ }
+ },
+ setAudioFactory: function(audioFactory) {
+ this.audioFactory = audioFactory;
}
}