47 BOOL _playRequestBeforeLoad;
48 HTMLAudioElement _audioTag;
54 #pragma mark Initialization
58 if (
self = [super init])
62 _audioTag = document.createElement(
"audio");
63 _audioTag.preload = YES;
64 _playRequestBeforeLoad = NO;
66 _audioTag.addEventListener(
"canplay",
function()
72 _audioTag.addEventListener(
"ended",
function()
78 _audioTag.addEventListener(
"error",
function()
94 - (id)initWithContentsOfFile:(
CPString)aFile byReference:(BOOL)byRef
96 if (
self = [
self init])
99 _audioTag.src = aFile;
111 - (id)initWithContentsOfURL:(
CPURL)aURL byReference:(BOOL)byRef
124 if (
self = [
self init])
135 #pragma mark Events listener
139 - (void)_soundDidload
143 if (_playRequestBeforeLoad)
145 _playRequestBeforeLoad = NO;
163 CPLog.error(
"Cannot load sound. Maybe the format of your sound is not compatible with your browser.");
168 #pragma mark Media controls
179 _playRequestBeforeLoad = YES;
205 _audioTag.currentTime = 0.0;
208 if (_delegate && [_delegate respondsToSelector:
@selector(sound:didFinishPlaying:)])
209 [_delegate sound:self didFinishPlaying:YES];
255 return _audioTag.loop;
263 - (void)setLoops:(BOOL)shouldLoop
265 _audioTag.loop = shouldLoop;
275 return _audioTag.volume;
283 - (void)setVolume:(
double)aVolume
287 else if (aVolume < 0.0)
290 _audioTag.volume = aVolume;
294 #pragma mark Accessors
303 return _audioTag.duration;
347 - (void)setDelegate:(
id)aValue