Permalink
Browse files

Added play_once method to play a preloaded sound resource only once

while it's still playing.
  • Loading branch information...
1 parent e4a03af commit 9cde770d489c89b0fb024dafda0d4dd9df18c3d1 @fwenzel fwenzel committed Mar 3, 2012
Showing with 8 additions and 1 deletion.
  1. +8 −1 js/core/sounds.js
View
@@ -30,7 +30,7 @@ define(function(require) {
// Play an audio file.
// src can either be the path to an audio file or the name
// of a sound resource from resources.json.
- play: function(src){
+ play: function(src) {
var player = this.get_next_player(),
preloaded = $('audio#preload-' + src);
@@ -41,6 +41,13 @@ define(function(require) {
}
player.play();
+ },
+
+ // Play an audio file, but do not play again while it's playing.
+ // src can only be a sound resource name from resources.json.
+ play_once: function(src) {
+ var snd = $('audio#preload-' + src);
+ if (snd.length) snd.get(0).play();
}
});

0 comments on commit 9cde770

Please sign in to comment.