|
62 | 62 | return; |
63 | 63 | } |
64 | 64 |
|
| 65 | + if ($(media).attr('autoplay') !== undefined && $(media).attr('autoplay') !== "false") { |
| 66 | + this.autoplay = true; |
| 67 | + } |
| 68 | + else { |
| 69 | + this.autoplay = false; |
| 70 | + } |
| 71 | + |
65 | 72 | // override defaults with values of data-* attributes |
66 | 73 |
|
67 | 74 | var includeTranscript = media.data('include-transcript'); |
|
184 | 191 | if (thisObj.countProperties(thisObj.tt) > 50) { |
185 | 192 | // close enough to ensure that most text variables are populated |
186 | 193 | thisObj.setup(); |
| 194 | + if (thisObj.startTime > 0 && !thisObj.autoplay) { |
| 195 | + // scrub ahead to startTime, but don't start playing |
| 196 | + // can't do this in media event listener |
| 197 | + // because in some browsers no media events are fired until media.play is requested |
| 198 | + // even if preload="auto" |
| 199 | + thisObj.onMediaUpdateTime(); |
| 200 | + } |
187 | 201 | } |
188 | 202 | else { |
189 | 203 | // can't continue loading player with no text |
|
199 | 213 | AblePlayer.prototype.setup = function() { |
200 | 214 | var thisObj = this; |
201 | 215 | if (this.debug && this.startTime > 0) { |
202 | | - console.log('Will start media at ' + startTime + ' seconds'); |
| 216 | + console.log('Will start media at ' + this.startTime + ' seconds'); |
203 | 217 | } |
204 | | - |
205 | 218 | this.reinitialize().then(function () { |
206 | 219 | if (!thisObj.player) { |
207 | 220 | // No player for this media, show last-line fallback. |
|
3960 | 3973 | })(); |
3961 | 3974 | (function () { |
3962 | 3975 | AblePlayer.prototype.seekTo = function (newTime) { |
3963 | | - // TODO: How do we want startTime functionality to work? |
3964 | 3976 |
|
3965 | 3977 | if (this.player === 'html5') { |
3966 | 3978 | var seekable; |
3967 | 3979 |
|
3968 | 3980 | this.startTime = newTime; |
3969 | 3981 | // Check HTML5 media "seekable" property to be sure media is seekable to startTime |
3970 | 3982 | seekable = this.media.seekable; |
| 3983 | + |
3971 | 3984 | if (seekable.length > 0 && this.startTime >= seekable.start(0) && this.startTime <= seekable.end(0)) { |
3972 | 3985 | this.media.currentTime = this.startTime; |
3973 | 3986 | } |
|
4244 | 4257 | else if (this.player === 'youtube') { |
4245 | 4258 | this.youtubePlayer.playVideo(); |
4246 | 4259 | } |
4247 | | - this.startedPlaying = true; |
| 4260 | + this.startedPlaying = true; |
4248 | 4261 | }; |
4249 | 4262 |
|
4250 | 4263 | // Right now, update the seekBar values based on current duration and time. |
|
4508 | 4521 | else { |
4509 | 4522 | this.pauseMedia(); |
4510 | 4523 | } |
4511 | | - |
4512 | 4524 | this.refreshControls(); |
4513 | 4525 | }; |
4514 | 4526 |
|
|
5359 | 5371 | (function () { |
5360 | 5372 | // Media events |
5361 | 5373 | AblePlayer.prototype.onMediaUpdateTime = function () { |
5362 | | - if (this.startTime && !this.startedPlaying) { |
5363 | | - // try seeking again, if seeking failed on canplay or canplaythrough |
5364 | | - this.seekTo(this.startTime); |
5365 | | - this.playMedia(); |
5366 | | - } |
5367 | | - |
| 5374 | + if (!this.startedPlaying) { |
| 5375 | + if (this.startTime) { |
| 5376 | + if (this.startTime === this.media.currentTime) { |
| 5377 | + // media has already scrubbed to start time |
| 5378 | + if (this.autoplay) { |
| 5379 | + this.playMedia(); |
| 5380 | + } |
| 5381 | + } |
| 5382 | + else { |
| 5383 | + // continue seeking ahead until currentTime == startTime |
| 5384 | + this.seekTo(this.startTime); |
| 5385 | + } |
| 5386 | + } |
| 5387 | + else { |
| 5388 | + // autoplay should generally be avoided unless a startTime is provided |
| 5389 | + // but we'll trust the developer to be using this feature responsibly |
| 5390 | + if (this.autoplay) { |
| 5391 | + this.playMedia(); |
| 5392 | + } |
| 5393 | + } |
| 5394 | + } |
| 5395 | + |
5368 | 5396 | // show highlight in transcript |
5369 | 5397 | if (this.prefHighlight === 1) { |
5370 | 5398 | this.highlightTranscript(this.getElapsed()); |
|
5659 | 5687 | thisObj.onMediaNewSourceLoad(); |
5660 | 5688 | }) |
5661 | 5689 | .on('canplay',function() { |
| 5690 | + if (thisObj.debug) { |
| 5691 | + console.log('canplay event'); |
| 5692 | + } |
5662 | 5693 | if (thisObj.startTime && !thisObj.startedPlaying) { |
5663 | 5694 | thisObj.seekTo(thisObj.startTime); |
5664 | 5695 | } |
5665 | 5696 | }) |
5666 | 5697 | .on('canplaythrough',function() { |
| 5698 | + if (thisObj.debug) { |
| 5699 | + console.log('canplaythrough event'); |
| 5700 | + } |
5667 | 5701 | if (thisObj.startTime && !thisObj.startedPlaying) { |
5668 | 5702 | // try again, if seeking failed on canplay |
5669 | 5703 | thisObj.seekTo(thisObj.startTime); |
|
5678 | 5712 | .on('progress', function() { |
5679 | 5713 | thisObj.refreshControls(); |
5680 | 5714 | }) |
5681 | | - .on('waiting',function() { |
| 5715 | + .on('waiting',function() { |
5682 | 5716 | thisObj.refreshControls(); |
5683 | 5717 | }) |
5684 | 5718 | .on('durationchange',function() { |
|
0 commit comments