Skip to content

Commit 62944fb

Browse files
author
OJay Robinson
committed
added SoundInstance.startTime getter / setter
updated TestSuite to include instance startTime and duration sliders
1 parent 087a4dd commit 62944fb

9 files changed

Lines changed: 185 additions & 27 deletions

VERSIONS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ CRITICAL (may break existing content):
2222
example: {id:"music", src:{mp3:"myMP3Path/music.mp3", ogg:"myOggPath/musicWithoutExtension"}}
2323
- fixed setting duration on an existing SoundInstance in HTMLAudioSoundInstance
2424
- fixed setting duration on an existing SoundInstance in WebAudioPlugin
25+
- added SoundInstance.startTime support
2526

2627
Version 0.6.0 [December 12, 2014]
2728
************************************************************************************************************************

docs/soundjs_docs-NEXT.zip

1.87 KB
Binary file not shown.

examples/TestSuite.html

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
.startTimeSlider,
1818
.durationSlider,
1919
.masterVolumeSlider,
20-
.loopSlider {
20+
.loopSlider,
21+
.instanceLoopSlider,
22+
.instanceStartTimeSlider,
23+
.instanceDurationSlider
24+
{
2125
width: 200px;
2226
}
2327
</style>
@@ -215,6 +219,25 @@ <h1>Test Suite</h1>
215219
<td><label for="pos" id="posValue">0</label></td>
216220
</tr>
217221
</table>
222+
<table border="0" width="400" cellpadding="5" cellspacing="5">
223+
<label>Instance Audio Sprite Properties</label>
224+
<tr>
225+
<td><label for="instanceStartTime">Instance StartTime</label></td>
226+
<td>
227+
<div class="instanceStartTimeSlider" id="instanceStartTime"></div>
228+
</td>
229+
<td><label for="instanceStartTime" id="instanceStartTimeValue">0 seconds</label>
230+
</td>
231+
</tr>
232+
<tr>
233+
<td><label for="instanceDuration">Instance Duration</label></td>
234+
<td>
235+
<div class="instanceDurationSlider" id="instanceDuration"></div>
236+
</td>
237+
<td><label for="instanceDuration" id="instanceDurationValue">0 seconds</label>
238+
</td>
239+
</tr>
240+
</table>
218241
</form>
219242

220243
</div>
@@ -366,6 +389,22 @@ <h2>Sorry!</h2>
366389
change: handleSliderChange
367390
});
368391

392+
$(".instanceStartTimeSlider").slider({value: 0,
393+
min: 0,
394+
max: 10,
395+
disabled: true,
396+
change: handleSliderChange
397+
});
398+
$(".instanceStartTimeSlider").data("units", "second");
399+
400+
$(".instanceDurationSlider").slider({value: 0,
401+
min: 0,
402+
max: 10,
403+
disabled: true,
404+
change: handleSliderChange
405+
});
406+
$(".instanceDurationSlider").data("units", "second");
407+
369408
$("#nowPlaying").change(selectInstance);
370409
$("#playBtn").click(function (event) {
371410
var instance = getInstance();
@@ -456,6 +495,20 @@ <h2>Sorry!</h2>
456495
clearInterval(audioInterval);
457496
});
458497

498+
$(".instanceStartTimeSlider").on('slidestop', function (event) {
499+
var instance = getInstance();
500+
if (instance == null) {return;}
501+
var value = $(this).slider("option", "value");
502+
instance.startTime = value * 1000;
503+
});
504+
505+
$(".instanceDurationSlider").on('slidestop', function (event) {
506+
var instance = getInstance();
507+
if (instance == null) {return;}
508+
var value = $(this).slider("option", "value");
509+
instance.duration = value * 1000;
510+
});
511+
459512
enableSet("sound", false);
460513
enableSet("instance", false);
461514

@@ -656,6 +709,14 @@ <h2>Sorry!</h2>
656709
setPosSlider();
657710
audioInterval = setInterval(setPosSlider, intervalTime);
658711

712+
value = instance.startTime / 1000 | 0;
713+
$(".instanceStartTimeSlider").slider("value", value);
714+
$("#instaceStartTimeValue").text(value);
715+
716+
value = instance.duration / 1000 | 0;
717+
$(".instanceDurationSlider").slider("value", value);
718+
$("#instaceDurationpValue").text(value);
719+
659720
$("#pauseBtn").attr("value", instance.paused ? "Resume" : "Pause");
660721
$("#muteBtn").attr("value", instance.muted ? "Unmute" : "Mute");
661722
} else {
@@ -677,7 +738,7 @@ <h2>Sorry!</h2>
677738
enableItems("playControls", enabled, ["playSoundBtn", "interrupt", "loop", "delay", "offset", "startTime", "duration"]);
678739
break;
679740
case "instance":
680-
enableItems("instanceControls", enabled, ["play", "pause", "stop", "clear", "volume", "instanceLoop", "pan", "pos", "mute"]);
741+
enableItems("instanceControls", enabled, ["play", "pause", "stop", "clear", "volume", "instanceLoop", "pan", "pos", "mute", "instanceStartTime", "instanceDuration"]);
681742
break;
682743
}
683744
}

lib/flashaudioplugin-NEXT.combined.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,6 @@ this.createjs = this.createjs || {};
15681568
* @type String
15691569
* @static
15701570
**/
1571-
s.buildDate = /*=date*/"Tue, 03 Mar 2015 19:06:51 GMT"; // injected by build process
1571+
s.buildDate = /*=date*/"Tue, 03 Mar 2015 22:54:53 GMT"; // injected by build process
15721572

15731573
})();

lib/flashaudioplugin-NEXT.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/soundjs-NEXT.combined.js

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ this.createjs = this.createjs || {};
3030
* @type String
3131
* @static
3232
**/
33-
s.buildDate = /*=date*/"Tue, 03 Mar 2015 19:06:51 GMT"; // injected by build process
33+
s.buildDate = /*=date*/"Tue, 03 Mar 2015 22:54:53 GMT"; // injected by build process
3434

3535
})();
3636

@@ -4992,16 +4992,6 @@ this.createjs = this.createjs || {};
49924992

49934993

49944994
// private properties
4995-
/**
4996-
* Audio sprite property used to determine the starting offset.
4997-
* @type {Number}
4998-
* @default null
4999-
* @protected
5000-
*/
5001-
this._startTime = Math.max(0, startTime || 0);
5002-
//TODO add a getter / setter for startTime?
5003-
5004-
50054995
// Getter / Setter Properties
50064996
// OJR TODO find original reason that we didn't use defined functions. I think it was performance related
50074997
/**
@@ -5035,6 +5025,19 @@ this.createjs = this.createjs || {};
50355025
set: this.setPan
50365026
});
50375027

5028+
/**
5029+
* Audio sprite property used to determine the starting offset.
5030+
* @property startTime
5031+
* @type {Number}
5032+
* @default 0
5033+
* @since 0.6.1
5034+
*/
5035+
this._startTime = Math.max(0, startTime || 0);
5036+
Object.defineProperty(this, "startTime", {
5037+
get: this.getStartTime,
5038+
set: this.setStartTime
5039+
});
5040+
50385041
/**
50395042
* The length of the audio clip, in milliseconds.
50405043
*
@@ -5406,6 +5409,32 @@ this.createjs = this.createjs || {};
54065409
return this;
54075410
};
54085411

5412+
/**
5413+
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/startTime:property"}}{{/crossLink}} directly as a property
5414+
*
5415+
* @deprecated
5416+
* @method getStartTime
5417+
* @return {Number} The startTime of the sound instance in milliseconds.
5418+
*/
5419+
p.getStartTime = function () {
5420+
return this._startTime;
5421+
};
5422+
5423+
/**
5424+
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/startTime:property"}}{{/crossLink}} directly as a property
5425+
*
5426+
* @deprecated
5427+
* @method setStartTime
5428+
* @param {number} value The new startTime time in milli seconds.
5429+
* @return {AbstractSoundInstance} Returns reference to itself for chaining calls
5430+
*/
5431+
p.setStartTime = function (value) {
5432+
if (value == this._startTime) { return this; }
5433+
this._startTime = Math.max(0, value || 0);
5434+
this._updateStartTime();
5435+
return this;
5436+
};
5437+
54095438
/**
54105439
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/duration:property"}}{{/crossLink}} directly as a property
54115440
*
@@ -5624,6 +5653,16 @@ this.createjs = this.createjs || {};
56245653
// plugin specific code
56255654
};
56265655

5656+
/**
5657+
* Internal function used to update the startTime of the audio.
5658+
* @method _updateStartTime
5659+
* @protected
5660+
* @since 0.6.1
5661+
*/
5662+
p._updateStartTime = function () {
5663+
// plugin specific code
5664+
};
5665+
56275666
/**
56285667
* Internal function used to update the duration of the audio.
56295668
* @method _updateDuration
@@ -7148,6 +7187,15 @@ this.createjs = this.createjs || {};
71487187
}
71497188
};
71507189

7190+
p.updateStartTime = function () {
7191+
this._audioSpriteStopTime = (this._startTime + this._duration) * 0.001;
7192+
7193+
if(this.playState == createjs.Sound.PLAY_SUCCEEDED) {
7194+
this._playbackResource.removeEventListener(createjs.HTMLAudioPlugin._AUDIO_ENDED, this._endedHandler, false);
7195+
this._playbackResource.addEventListener(createjs.HTMLAudioPlugin._TIME_UPDATE, this._audioSpriteEndHandler, false);
7196+
}
7197+
};
7198+
71517199
p._updateDuration = function () {
71527200
this._audioSpriteStopTime = (this._startTime + this._duration) * 0.001;
71537201

lib/soundjs-NEXT.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/soundjs/AbstractSoundInstance.js

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,6 @@ this.createjs = this.createjs || {};
119119

120120

121121
// private properties
122-
/**
123-
* Audio sprite property used to determine the starting offset.
124-
* @type {Number}
125-
* @default null
126-
* @protected
127-
*/
128-
this._startTime = Math.max(0, startTime || 0);
129-
//TODO add a getter / setter for startTime?
130-
131-
132122
// Getter / Setter Properties
133123
// OJR TODO find original reason that we didn't use defined functions. I think it was performance related
134124
/**
@@ -162,6 +152,19 @@ this.createjs = this.createjs || {};
162152
set: this.setPan
163153
});
164154

155+
/**
156+
* Audio sprite property used to determine the starting offset.
157+
* @property startTime
158+
* @type {Number}
159+
* @default 0
160+
* @since 0.6.1
161+
*/
162+
this._startTime = Math.max(0, startTime || 0);
163+
Object.defineProperty(this, "startTime", {
164+
get: this.getStartTime,
165+
set: this.setStartTime
166+
});
167+
165168
/**
166169
* The length of the audio clip, in milliseconds.
167170
*
@@ -533,6 +536,32 @@ this.createjs = this.createjs || {};
533536
return this;
534537
};
535538

539+
/**
540+
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/startTime:property"}}{{/crossLink}} directly as a property
541+
*
542+
* @deprecated
543+
* @method getStartTime
544+
* @return {Number} The startTime of the sound instance in milliseconds.
545+
*/
546+
p.getStartTime = function () {
547+
return this._startTime;
548+
};
549+
550+
/**
551+
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/startTime:property"}}{{/crossLink}} directly as a property
552+
*
553+
* @deprecated
554+
* @method setStartTime
555+
* @param {number} value The new startTime time in milli seconds.
556+
* @return {AbstractSoundInstance} Returns reference to itself for chaining calls
557+
*/
558+
p.setStartTime = function (value) {
559+
if (value == this._startTime) { return this; }
560+
this._startTime = Math.max(0, value || 0);
561+
this._updateStartTime();
562+
return this;
563+
};
564+
536565
/**
537566
* DEPRECATED, please use {{#crossLink "AbstractSoundInstance/duration:property"}}{{/crossLink}} directly as a property
538567
*
@@ -751,6 +780,16 @@ this.createjs = this.createjs || {};
751780
// plugin specific code
752781
};
753782

783+
/**
784+
* Internal function used to update the startTime of the audio.
785+
* @method _updateStartTime
786+
* @protected
787+
* @since 0.6.1
788+
*/
789+
p._updateStartTime = function () {
790+
// plugin specific code
791+
};
792+
754793
/**
755794
* Internal function used to update the duration of the audio.
756795
* @method _updateDuration

src/soundjs/htmlaudio/HTMLAudioSoundInstance.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,15 @@ this.createjs = this.createjs || {};
250250
}
251251
};
252252

253+
p.updateStartTime = function () {
254+
this._audioSpriteStopTime = (this._startTime + this._duration) * 0.001;
255+
256+
if(this.playState == createjs.Sound.PLAY_SUCCEEDED) {
257+
this._playbackResource.removeEventListener(createjs.HTMLAudioPlugin._AUDIO_ENDED, this._endedHandler, false);
258+
this._playbackResource.addEventListener(createjs.HTMLAudioPlugin._TIME_UPDATE, this._audioSpriteEndHandler, false);
259+
}
260+
};
261+
253262
p._updateDuration = function () {
254263
this._audioSpriteStopTime = (this._startTime + this._duration) * 0.001;
255264

0 commit comments

Comments
 (0)