Merge pull request #560 from damencho/seek-on-start-paused

Seeks in video when we start in paused state.
This commit is contained in:
yanas 2016-03-28 13:56:09 -05:00
commit 0bde7de37b
2 changed files with 25 additions and 12 deletions

View File

@ -1101,6 +1101,7 @@ export default {
else { else {
// in case of paused, in order to allow late users to join // in case of paused, in order to allow late users to join
// paused // paused
room.removeCommand(Commands.SHARED_VIDEO);
room.sendCommand(Commands.SHARED_VIDEO, { room.sendCommand(Commands.SHARED_VIDEO, {
value: url, value: url,
attributes: { attributes: {

View File

@ -184,17 +184,7 @@ export default class SharedVideoManager {
if (attributes.state == 'playing') { if (attributes.state == 'playing') {
// check received time and current time this.processTime(player, attributes);
let currentPosition = player.getCurrentTime();
let diff = Math.abs(attributes.time - currentPosition);
// if we drift more than the interval for checking
// sync, the interval is in milliseconds
if(diff > updateInterval/1000) {
console.info("DDD Player seekTo:", attributes.time,
" current time is:", currentPosition, " diff:", diff);
player.seekTo(attributes.time);
}
// lets check the volume // lets check the volume
if (attributes.volume !== undefined && if (attributes.volume !== undefined &&
@ -209,6 +199,28 @@ export default class SharedVideoManager {
} else if (attributes.state == 'pause') { } else if (attributes.state == 'pause') {
// if its not paused, pause it // if its not paused, pause it
player.pauseVideo(); player.pauseVideo();
this.processTime(player, attributes);
}
}
/**
* Check for time in attributes and if needed seek in current player
* @param player the player to operate over
* @param attributes the attributes with the player state we want
*/
processTime (player, attributes)
{
// check received time and current time
let currentPosition = player.getCurrentTime();
let diff = Math.abs(attributes.time - currentPosition);
// if we drift more than the interval for checking
// sync, the interval is in milliseconds
if(diff > updateInterval/1000) {
console.info("Player seekTo:", attributes.time,
" current time is:", currentPosition, " diff:", diff);
player.seekTo(attributes.time);
} }
} }
@ -226,7 +238,7 @@ export default class SharedVideoManager {
// if its paused and haven't been pause - send paused // if its paused and haven't been pause - send paused
if (state === YT.PlayerState.PAUSED && sendPauseEvent) { if (state === YT.PlayerState.PAUSED && sendPauseEvent) {
this.emitter.emit(UIEvents.UPDATE_SHARED_VIDEO, this.emitter.emit(UIEvents.UPDATE_SHARED_VIDEO,
this.url, 'pause'); this.url, 'pause', this.player.getCurrentTime());
} }
// if its playing and it was paused - send update with time // if its playing and it was paused - send update with time
// if its playing and was playing just send update with time // if its playing and was playing just send update with time