8000 fix Audio.stop and add Audio.pause · GameJs/gamejs@3c27943 · GitHub
[go: up one dir, main page]

Skip to content
Dismiss alert

Commit 3c27943

Browse files
committed
fix Audio.stop and add Audio.pause
1 parent 1edf9f6 commit 3c27943

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

src/gamejs/audio.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,19 @@ exports.Sound = function Sound(uriOrAudio) {
160160
*/
161161
this.stop = function() {
162162
channels.forEach(function(audio) {
163-
audio.stop();
163+
audio.pause();
164+
audio.load();
165+
audio.currentTime = 0;
166+
});
167+
};
168+
169+
/**
170+
* Pause the sound.
171+
* This will pause the playback of this Sound on any active Channels.
172+
*/
173+
this.pause = function() {
174+
channels.forEach(function(audio) {
175+
audio.pause();
164176
});
165177
};
166178

tests/audio.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var gamejs = require('gamejs');
2+
qModule('gamejs/audio');
3+
var surfaceEqual = QUnit.surfaceEqual;
4+
5+
var audio = null;
6+
QUnit.testStart(function() {
7+
audio = new gamejs.audio.Sound(document.getElementById('sound-fixture'));
8+
})
9+
10+
// this should just run through
11+
QUnit.test('basic', 0, function() {
12+
audio.play();
13+
audio.stop();
14+
audio.play();
15+
audio.pause();
16+
});

tests/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<!-- for testing the unit tests it's sometimes convinient to have a canvas present to
2222
output images -->
2323
<canvas id="gjs-canvas" width=800 height=600></canvas>
24+
<audio id="sound-fixture" src="./sound-fixture.wav"></audio>
2425
<h1 id="qunit-header">GameJs Test Suite</h1>
2526
<h2 id="qunit-banner"></h2>
2627
<div id="qunit-testrunner-toolbar"></div>

tests/main.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ gamejs.ready(function() {
66

77
// NOTE can't name it `gamejs` because that would conflict with above
88
// maybe yabble bug
9+
require('./audio');
910
require('./base64');
1011
require('./binaryheap');
1112
require('./draw');

tests/sound-fixture.wav

12.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)
0