rendered paste bodyIndex: nicontroller.js===================================================================--- nicontroller.js (リビジョン 38275)+++ nicontroller.js (作業コピー)@@ -274,24 +274,38 @@ return null; }, + get _flvplayerInfo() {+ var p = this._flvplayer();+ if (p._NicoPlayerControllerInfo === undefined) {+ p._NicoPlayerControllerInfo = {};+ }+ return p._NicoPlayerControllerInfo;+ },++ play: function(playStatus) {+ var p = this._flvplayer();+ p.ext_play(playStatus);+ this._flvplayerInfo.playStatus = playStatus;+ },+ togglePlay: function() { var p = this._flvplayer();- (p.ext_getStatus() !== this.constants.STATE_PLAYING)- ? p.ext_play(this.constants.PLAY)- : p.ext_play(this.constants.PAUSE);+ if (p.ext_getStatus() === 'end') {+ if (p.ext_getPlayheadTime() === p.ext_getTotalTime()) {+ p.ext_setPlayheadTime(0);+ this.play(this.constants.PLAY);+ return;+ }+ this.play(! this._flvplayerInfo.playStatus);+ return;+ } - if(p.ext_getStatus() === 'end') {- let base = p.ext_getPlayheadTime();- let self = this;- setTimeout(function () {- if (base !== p.ext_getPlayheadTime()) {- p.ext_play(self.constants.PAUSE);- } else {- p.ext_setPlayheadTime(0);- p.ext_play(self.constants.PLAY);- }- }, 100);+ if (this._flvplayerInfo.playStatus === undefined && p.ext_getPlayheadTime() === 0) {+ this.play(this.constants.PLAY);+ return; }++ this.play(p.ext_getStatus() !== this.constants.STATE_PLAYING ? this.constants.PLAY : this.constants.PAUSE); }, toggleMute: function() {@@ -369,6 +383,60 @@ seekBy: function(delta) { if(delta) {+ if (delta.match(/^(-?\d+)k$/)) {+ delta = parseInt(RegExp.$1, this.constants.CARDINAL_NUMBER);+ var p = this._flvplayer();+ var position = p.ext_getPlayheadTime();+ if (delta < 0) {+ if (position == 0) {+ return;+ }+ var prePosition = position;+ function waitProc(cond, proc, interval) {+ function func() {+ if (cond()) {+ proc();+ }+ else {+ setTimeout(func, interval);+ }+ }+ func();+ }+ function seekAndWait(proc) {+ waitProc(function() { return p.ext_getStatus() !== 'seeking'; }, proc, 0);+ }+ function seekWhile(cond, onNext, onFinish) {+ function func(pos) {+ var nextPos = onNext(pos);+ if (nextPos < 0) {+ nextPos = 0;+ }+ p.ext_setPlayheadTime(nextPos);+ function proc() {+ var tmpPosition = p.ext_getPlayheadTime();+ if (cond(tmpPosition)) {+ func(tmpPosition);+ }+ else {+ onFinish(tmpPosition);+ }+ }+ seekAndWait(proc);+ }+ func();+ }+ function onFinish(finishPos) {+ //seekWhile(function(pos) { return pos < prePosition; }, function(pos) { return (position = (pos ? pos : finishPos)) + 1; }, function() { p.ext_setPlayheadTime(position); });+ }+ seekWhile(function(pos) { return pos >= prePosition; }, function() { return position -= 5; }, onFinish);+ }+ else {+ position += 1;+ p.ext_setPlayheadTime(position);+ }+ return;+ } if(isNaN(delta)) throw new Error('assign signed number : seekBy()'); } else delta = this.constants.SEEKBY_DEFAULT;@@ -377,6 +445,12 @@ var position = p.ext_getPlayheadTime(); position += parseInt(delta, this.constants.CARDINAL_NUMBER); + if (position < 0) {+ position = 0;+ }+ else if (position > p.ext_getTotalTime()) {+ position = p.ext_getTotalTime();+ } p.ext_setPlayheadTime(position); },