-
Notifications
You must be signed in to change notification settings - Fork 0
/
ember-audio.js
106 lines (92 loc) · 2.68 KB
/
ember-audio.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
(function () {
EmberAudio = {
audioCache: {}
};
EmberAudio.object = Ember.Object.extend({
load: function(src) {
if (this.get('ready')) {
this.set('src', src);
EmberAudio.audiojsInstance.load(src);
} else {
// wait 'til we're ready, then load
setTimeout($.proxy(function() {
this.load(src);
}, this), 50);
}
},
play: function() {
if (this.get('ready')) {
EmberAudio.audiojsInstance.play();
}
},
playPause: function() {
if (this.get('ready')) {
EmberAudio.audiojsInstance.playPause();
} else {
// wait 'til we're ready, then playPause
setTimeout($.proxy(function() {
this.playPause();
}, this), 50);
}
},
pause: function() {
if (this.get('ready')) {
EmberAudio.audiojsInstance.pause();
}
},
reset: function() {
this.pause();
this.set('src', null);
this.set('playing', false);
this.set('position', null);
this.set('duration', null);
this.set('progress', null);
this.set('ended', false);
}
});
EmberAudio.object.reopenClass({
create: function() {
var instance = this._super({});
instance.reset();
return instance;
}
});
EmberAudio.instance = EmberAudio.object.create();
EmberAudio.audiojsInstance = new Audio5js({
swf_path: window.audio5jsSwfPath || '/audio5js.swf',
throw_errors: true,
format_time: false,
ready: function() {
EmberAudio.instance.set('ready', true);
}
});
EmberAudio.audiojsInstance.on('play', function () {
EmberAudio.instance.set('ended', false);
Ember.set('EmberAudio.instance.playing', true);
}, this);
EmberAudio.audiojsInstance.on('pause', function () {
EmberAudio.instance.set('playing', false);
}, this);
EmberAudio.audiojsInstance.on('ended', function () {
EmberAudio.instance.set('playing', false);
EmberAudio.instance.set('ended', true);
}, this);
EmberAudio.audiojsInstance.on('timeupdate', function (position, duration) {
if (position.toString().indexOf('NaN') != -1) {
alert('An error occurred playing audio, please refresh the page and try again.');
} else {
if (EmberAudio.instance.get('src')) {
EmberAudio.instance.set('position', position);
EmberAudio.instance.set('duration', duration);
}
}
}, this);
EmberAudio.audiojsInstance.on('progress', function (progress) {
if (EmberAudio.instance.get('src')) {
EmberAudio.instance.set('progress', progress);
}
}, this);
EmberAudio.audiojsInstance.on('error', function (error) {
alert(error.message);
}, this);
}).call(window);