Skip to content

Commit e9fb3f5

Browse files
committed
add 👊
1 parent 0e54415 commit e9fb3f5

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

app/angular.audio.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ angular.module('ngAudio', [])
115115
$willPlay = false,
116116
$willPause = false,
117117
$willRestart = false,
118+
$willChangePlaybackRate = false,
119+
$newPlaybackRate = false,
118120
$volumeToSet,
119121
$looping,
120122
$isMuting = false,
@@ -150,6 +152,11 @@ angular.module('ngAudio', [])
150152
$volumeToSet = volume;
151153
};
152154

155+
this.setPlaybackRate = function(rate) {
156+
$newPlaybackRate = rate;
157+
$willChangePlaybackRate = true;
158+
};
159+
153160
this.setMuting = function(muting) {
154161
$isMuting = muting;
155162
};
@@ -174,6 +181,7 @@ angular.module('ngAudio', [])
174181
progress: audioObject.progress,
175182
muting: audioObject.muting,
176183
loop: audioObject.loop,
184+
playbackRate: audioObject.playbackRate
177185
};
178186
}, function(newValue, oldValue) {
179187
if (newValue.currentTime !== oldValue.currentTime) {
@@ -187,10 +195,12 @@ angular.module('ngAudio', [])
187195
audioObject.setVolume(newValue.volume);
188196
}
189197

190-
if (newValue.volume !== oldValue.volume) {
191-
audioObject.setVolume(newValue.volume);
198+
if (newValue.playbackRate !== oldValue.playbackRate) {
199+
audioObject.setPlaybackRate(newValue.playbackRate);
192200
}
193201

202+
203+
194204
$looping = newValue.loop;
195205

196206
if (newValue.muting !== oldValue.muting) {
@@ -206,7 +216,7 @@ angular.module('ngAudio', [])
206216
audioObject.canPlay = true;
207217
});
208218

209-
audio.playbackRate = 0.5;
219+
210220
}, function(error) {
211221
audioObject.error = true;
212222
console.warn(error);
@@ -241,6 +251,11 @@ angular.module('ngAudio', [])
241251
$willPause = false;
242252
}
243253

254+
if ($willChangePlaybackRate) {
255+
audio.playbackRate = $newPlaybackRate;
256+
$willChangePlaybackRate = false;
257+
}
258+
244259
if ($volumeToSet) {
245260
audio.volume = $volumeToSet;
246261
$volumeToSet = undefined;

app/partial/audioEditView.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ <h3>
7373
<strong>audioObject.volume:</strong>The volume of the object as a percentage (0-1);
7474
</div>
7575
</div>
76+
<div class="form-group">
77+
<label class="col-md-4 control-label" for="prependedtext">Playback Rate</label>
78+
<div class="col-md-8">
79+
<div class="input-group">
80+
<span class="input-group-addon">Playback Rate</span>
81+
<input class='form-control' type=range min=0.5 max=1.5 step=0.01 ng-model='audio.playbackRate'>
82+
</div>
83+
<strong>audioObject.playbackRate:</strong>The speed the audio plays at. (0.5 - 1.5);
84+
</div>
85+
</div>
7686
</form>
7787

7888
<!-- <div class='hidden-sm' ng-include="'partial/audioTableView.html'"></div> -->

app/partial/ngAudioDocs.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ <h4>NgAudioObject Reference</h4>
129129
<p>Write - sets the current time of the of the sound as a percentage from 0 to 1.</p>
130130
</td>
131131
</tr>
132+
<tr>
133+
<td>playbackRate:number</td>
134+
<td>
135+
<p>
136+
Read - returns the speed that the sound is playing at, typically from 0.5 - 1.5.
137+
</p>
138+
<p>Write - sets the audio speed. Values between 0.5 and 1.5 are recommended.</p>
139+
</td>
140+
</tr>
132141
<tr>
133142
<td>muting:boolean</td>
134143
<td>

0 commit comments

Comments
 (0)