mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-12-06 12:45:32 +00:00
Merge branch 'fix-cpsound-firefox' of https://github.com/primalmotion/cappuccino into primalmotion-fix-cpsound-firefox
This commit is contained in:
commit
d926ad6221
1 file changed
+39
-10
+39
-10
@@ -25,6 +25,7 @@
|
||||
CPSoundLoadStateEmpty = 0;
|
||||
CPSoundLoadStateLoading = 1;
|
||||
CPSoundLoadStateCanBePlayed = 2;
|
||||
CPSoundLoadStateError = 3;
|
||||
|
||||
CPSoundPlayBackStatePlay = 0;
|
||||
CPSoundPlayBackStateStop = 1;
|
||||
@@ -63,11 +64,15 @@ CPSoundPlayBackStatePause = 2;
|
||||
_audioTag.addEventListener("canplay", function()
|
||||
{
|
||||
[self _soundDidload];
|
||||
});
|
||||
}, true);
|
||||
_audioTag.addEventListener("ended", function()
|
||||
{
|
||||
[self _soundDidEnd];
|
||||
});
|
||||
}, true);
|
||||
_audioTag.addEventListener("error", function()
|
||||
{
|
||||
[self _soundError];
|
||||
}, true);
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -137,31 +142,45 @@ CPSoundPlayBackStatePause = 2;
|
||||
[self stop];
|
||||
}
|
||||
|
||||
/*! @ignore
|
||||
*/
|
||||
- (void)_soundError
|
||||
{
|
||||
_loadStatus = CPSoundLoadStateError;
|
||||
CPLog.error("Cannot load sound. Maybe the format of your sound is not compatible with your browser.");
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Media controls
|
||||
|
||||
/*!
|
||||
Play the sound.
|
||||
|
||||
@return YES when the receiver is playing its audio data, NO otherwise.
|
||||
*/
|
||||
- (void)play
|
||||
- (BOOL)play
|
||||
{
|
||||
if ((_loadStatus !== CPSoundLoadStateCanBePlayed)
|
||||
|| (_playBackStatus === CPSoundPlayBackStatePlay))
|
||||
return;
|
||||
return NO;
|
||||
|
||||
_audioTag.play();
|
||||
_playBackStatus = CPSoundPlayBackStatePlay;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
/*!
|
||||
Stop the sound.
|
||||
|
||||
@return YES when the receiver is playing its audio data, NO otherwise.
|
||||
*/
|
||||
- (void)stop
|
||||
- (BOOL)stop
|
||||
{
|
||||
if ((_loadStatus !== CPSoundLoadStateCanBePlayed)
|
||||
|| (_playBackStatus === CPSoundPlayBackStateStop))
|
||||
return;
|
||||
return NO;
|
||||
|
||||
_audioTag.pause();
|
||||
_audioTag.currentTime = 0.0;
|
||||
@@ -169,32 +188,42 @@ CPSoundPlayBackStatePause = 2;
|
||||
|
||||
if (_delegate && [_delegate respondsToSelector:@selector(sound:didFinishPlaying:)])
|
||||
[_delegate sound:self didFinishPlaying:YES];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
/*!
|
||||
Pause the sound.
|
||||
|
||||
@return YES when the receiver is playing its audio data, NO otherwise.
|
||||
*/
|
||||
- (void)pause
|
||||
- (BOOL)pause
|
||||
{
|
||||
if ((_loadStatus !== CPSoundLoadStateCanBePlayed)
|
||||
|| (_playBackStatus === CPSoundPlayBackStatePause))
|
||||
return;
|
||||
return NO;
|
||||
|
||||
_audioTag.pause();
|
||||
_playBackStatus = CPSoundPlayBackStatePause;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
/*!
|
||||
Resume playback of a paused sound.
|
||||
|
||||
@return YES when the receiver is playing its audio data, NO otherwise.
|
||||
*/
|
||||
- (void)resume
|
||||
- (BOOL)resume
|
||||
{
|
||||
if ((_loadStatus !== CPSoundLoadStateCanBePlayed)
|
||||
|| (_playBackStatus !== CPSoundPlayBackStatePause))
|
||||
return;
|
||||
return NO;
|
||||
|
||||
_audioTag.play();
|
||||
_playBackStatus = CPSoundPlayBackStatePlay;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
Reference in new issue
Block a user