Skip to content

Commit

Permalink
Merge pull request #2723 from jwplayer/feature/api-getCurrentTime
Browse files Browse the repository at this point in the history
Add getCurrentTime() Public API Method
  • Loading branch information
robwalch committed Feb 22, 2018
2 parents 7e50240 + 803cea5 commit 59d0813
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 0 deletions.
103 changes: 103 additions & 0 deletions docs/api/Api.html
Expand Up @@ -2787,6 +2787,109 @@ <h5>Returns:</h5>



<h4 class="name" id="getCurrentTime"><span class="type-signature"></span>getCurrentTime<span class="signature">()</span><span class="type-signature"> &rarr; {number}</span></h4>






<div class="description">
<p>Gets the current value for video.currentTime</p>
</div>













<dl class="details">
































</dl>













<h5>Returns:</h5>


<div class="param-desc">
<p>The value for video.currentTime in seconds</p>
</div>



<dl>
<dt>
Type
</dt>
<dd>

<span class="param-type">number</span>


</dd>
</dl>













<h4 class="name" id="getDuration"><span class="type-signature"></span>getDuration<span class="signature">()</span><span class="type-signature"> &rarr; {number}</span></h4>


Expand Down
8 changes: 8 additions & 0 deletions src/js/api/api.js
Expand Up @@ -340,6 +340,14 @@ export default function Api(element) {
return core.getCurrentQuality();
},

/**
* Gets the current value for video.currentTime
* @returns {number} The value for video.currentTime in seconds
*/
getCurrentTime() {
return core.get('currentTime');
},

/**
* Gets the duration of the current playlist item.
* @returns {number} The duration in seconds.
Expand Down
1 change: 1 addition & 0 deletions src/js/controller/model.js
Expand Up @@ -216,6 +216,7 @@ const Model = function() {
this.set('playRejected', false);
this.attributes.itemMeta = {};
mediaModel.set('position', position);
mediaModel.set('currentTime', 0);
mediaModel.set('duration', duration);
};
};
Expand Down
1 change: 1 addition & 0 deletions src/js/model/player-model.js
Expand Up @@ -15,4 +15,5 @@ export const INITIAL_MEDIA_STATE = {
position: 0,
duration: 0,
buffer: 0,
currentTime: 0,
};
1 change: 1 addition & 0 deletions src/js/program/media-controller.js
Expand Up @@ -228,6 +228,7 @@ export default class MediaController extends Eventable {
const mediaModelState = mediaModel.attributes;
mediaModel.srcReset();
mediaModelState.position = position;
mediaModelState.currentTime = 0;
mediaModelState.duration = duration;

this.item = item;
Expand Down
1 change: 1 addition & 0 deletions src/js/program/program-listeners.js
Expand Up @@ -59,6 +59,7 @@ export function ProviderListener(mediaController) {
/* falls through to update duration while media is loaded */
case MEDIA_TIME: {
mediaModel.set('position', data.position);
mediaModel.set('currentTime', data.currentTime);
const duration = data.duration;
if (_isNumber(duration) && !_isNaN(duration)) {
mediaModel.set('duration', duration);
Expand Down
1 change: 1 addition & 0 deletions src/js/providers/video-listener-mixin.js
Expand Up @@ -66,6 +66,7 @@ const VideoListenerMixin = {
var timeEventObject = {
position,
duration,
currentTime: this.video.currentTime,
metadata: {
currentTime: this.video.currentTime
}
Expand Down
1 change: 1 addition & 0 deletions test/data/api-methods.js
Expand Up @@ -24,6 +24,7 @@ export default {
getCurrentAudioTrack: null,
getCurrentCaptions: null,
getCurrentQuality: null,
getCurrentTime: null,
getDuration: null,
getEnvironment: null,
getFullscreen: null,
Expand Down
1 change: 1 addition & 0 deletions test/data/model-properties.js
Expand Up @@ -93,6 +93,7 @@ export default {
item: 0,
duration: 0,
position: 0,
currentTime: 0,
flashBlocked: false,
buffer: 0,
itemMeta: {},
Expand Down

0 comments on commit 59d0813

Please sign in to comment.