Skip to content

Commit 0fe7dac

Browse files
committed
adjust PlayerInstance method.
1 parent 879b0d7 commit 0fe7dac

File tree

1 file changed

+74
-105
lines changed

1 file changed

+74
-105
lines changed

src/js-player-module-brightcove.js

Lines changed: 74 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -190,119 +190,88 @@ export class PLAYER_MODULE_BRIGHTCOVE {
190190
PlayerInstance(){
191191
let _that = this;
192192

193-
let checkPlayerTest = ()=>{
194-
195-
// Set Instance
196-
this.Player = videojs(this.CONFIG.player_id);
197-
198-
// Set PlayerJson
199-
this.PlayerJson = this.Player.toJSON();
200-
201-
// Set MediaInfo
202-
this.PlayerMediaInfo = this.Player.mediainfo;
203-
204-
this.EventPlay();
205-
this.EventPause();
206-
this.EventStop();
207-
this.EventMute();
208-
this.EventVolon();
209-
this.EventVoloff();
210-
this.EventBtnFull();
211-
this.EventSeekbarVol();
212-
this.EventSeekbarTime();
213-
this.EventChangeVideo();
214-
215-
this.AddGlobalObject();
216-
217-
let _loadeddata_flg = false;
218-
videojs(this.CONFIG.player_id).on('loadedmetadata', ()=>{
219-
if(_loadeddata_flg) return false;
220-
_loadeddata_flg = true;
221-
this.SetVolume();
222-
this.SetInfo();
223-
this.SetPoster();
224-
this.Update();
225-
if(_that.on.PlayerInit && typeof(_that.on.PlayerInit) === 'function') _that.on.PlayerInit(_that, _that.Player);
226-
});
227-
videojs(this.CONFIG.player_id).on('loadeddata', ()=>{
228-
if(_loadeddata_flg) return false;
229-
_loadeddata_flg = true;
230-
this.SetVolume();
231-
this.SetInfo();
232-
this.SetPoster();
233-
this.Update();
234-
if(_that.on.PlayerInit && typeof(_that.on.PlayerInit) === 'function') _that.on.PlayerInit(_that, _that.Player);
235-
});
236-
237-
// For Timeupdate.
238-
videojs(this.CONFIG.player_id).on('timeupdate', ()=>{
239-
this.Update();
240-
});
241-
242-
// For Volume change.
243-
videojs(this.CONFIG.player_id).on('volumechange', ()=>{
244-
// 音量バーの更新(%)
245-
let _volume = this.Player.volume();
193+
// Set Instance
194+
this.Player = videojs(this.CONFIG.player_id);
195+
196+
// Set PlayerJson
197+
this.PlayerJson = this.Player.toJSON();
198+
199+
// Set MediaInfo
200+
this.PlayerMediaInfo = this.Player.mediainfo;
201+
202+
this.EventPlay();
203+
this.EventPause();
204+
this.EventStop();
205+
this.EventMute();
206+
this.EventVolon();
207+
this.EventVoloff();
208+
this.EventBtnFull();
209+
this.EventSeekbarVol();
210+
this.EventSeekbarTime();
211+
this.EventChangeVideo();
212+
213+
this.AddGlobalObject();
214+
215+
let _loadeddata_flg = false;
216+
this.Player.on('loadedmetadata', ()=>{
217+
if(_loadeddata_flg) return false;
218+
_loadeddata_flg = true;
219+
this.SetVolume();
220+
this.SetInfo();
221+
this.SetPoster();
222+
this.Update();
223+
if(_that.on.PlayerInit && typeof(_that.on.PlayerInit) === 'function') _that.on.PlayerInit(_that, _that.Player);
224+
});
225+
this.Player.on('loadeddata', ()=>{
226+
if(_loadeddata_flg) return false;
227+
_loadeddata_flg = true;
228+
this.SetVolume();
229+
this.SetInfo();
230+
this.SetPoster();
231+
this.Update();
232+
if(_that.on.PlayerInit && typeof(_that.on.PlayerInit) === 'function') _that.on.PlayerInit(_that, _that.Player);
233+
});
246234

247-
DOM.setStyle( this.$.uiSeekbarVolCover, { width : (_volume * 100) + '%' } );
235+
// For Timeupdate.
236+
this.Player.on('timeupdate', ()=>{
237+
this.Update();
238+
});
248239

249-
if(_that.on.VolumeChange && typeof(_that.on.VolumeChange) === 'function'){
250-
_that.on.VolumeChange({
251-
volume: PLAYER_MODULE_BRIGHTCOVE.toFixedNumber(_volume, 3),
252-
par : PLAYER_MODULE_BRIGHTCOVE.toFixedNumber(_volume * 100, 1)
253-
});
254-
}
255-
});
240+
// For Volume change.
241+
this.Player.on('volumechange', ()=>{
242+
// 音量バーの更新(%)
243+
let _volume = this.Player.volume();
256244

257-
// For Ended movie paly.
258-
videojs(this.CONFIG.player_id).on('ended', ()=>{
259-
this.Stop();
260-
if(_that.on.PlayerEnded && typeof(_that.on.PlayerEnded) === 'function') _that.on.PlayerEnded(_that, _that.Player);
261-
});
245+
DOM.setStyle( this.$.uiSeekbarVolCover, { width : (_volume * 100) + '%' } );
262246

263-
videojs(this.CONFIG.player_id).on('play', ()=>{
264-
this.ClassOn();
265-
if(_that.on.PlayerPlay && typeof(_that.on.PlayerPlay) === 'function') _that.on.PlayerPlay(_that, _that.Player);
266-
});
247+
if(_that.on.VolumeChange && typeof(_that.on.VolumeChange) === 'function'){
248+
_that.on.VolumeChange({
249+
volume: PLAYER_MODULE_BRIGHTCOVE.toFixedNumber(_volume, 3),
250+
par : PLAYER_MODULE_BRIGHTCOVE.toFixedNumber(_volume * 100, 1)
251+
});
252+
}
253+
});
267254

268-
videojs(this.CONFIG.player_id).on('pause', ()=>{
269-
this.ClassOff();
270-
if(_that.on.PlayerPause && typeof(_that.on.PlayerPause) === 'function') _that.on.PlayerPause(_that, _that.Player);
271-
});
255+
// For Ended movie paly.
256+
this.Player.on('ended', ()=>{
257+
this.Stop();
258+
if(_that.on.PlayerEnded && typeof(_that.on.PlayerEnded) === 'function') _that.on.PlayerEnded(_that, _that.Player);
259+
});
272260

273-
// For Error
274-
videojs(this.CONFIG.player_id).on( 'error' , ()=>{
275-
console.log(err);
276-
});
277-
};
261+
this.Player.on('play', ()=>{
262+
this.ClassOn();
263+
if(_that.on.PlayerPlay && typeof(_that.on.PlayerPlay) === 'function') _that.on.PlayerPlay(_that, _that.Player);
264+
});
278265

279-
// Check Player try loaded.
280-
let checkPlayerFlg = false;
281-
let checkPlayerCount = 0;
282-
let checkPlayerLimitCount = 100;
283-
let checkPlayer = setInterval(()=>{
284-
try {
285-
videojs(this.CONFIG.player_id).mediainfo.name;
286-
if(videojs(this.CONFIG.player_id).mediainfo.name){
287-
checkPlayerFlg = true;
288-
}
289-
} catch (e) {
290-
checkPlayerFlg = false;
291-
// console.log(e.name, e.message);
292-
}
293-
// Check upper limit of action to try.
294-
if(checkPlayerCount >= checkPlayerLimitCount){
295-
clearInterval(checkPlayer);
296-
console.log('ERROR: not movie loaded.');
297-
} else {
298-
if(checkPlayerFlg){
299-
clearInterval(checkPlayer);
300-
checkPlayerTest();
301-
}
302-
}
303-
checkPlayerCount++;
304-
}, 100);
266+
this.Player.on('pause', ()=>{
267+
this.ClassOff();
268+
if(_that.on.PlayerPause && typeof(_that.on.PlayerPause) === 'function') _that.on.PlayerPause(_that, _that.Player);
269+
});
305270

271+
// For Error
272+
this.Player.on( 'error' , ()=>{
273+
console.log(err);
274+
});
306275
}
307276

308277
AddGlobalObject(){

0 commit comments

Comments
 (0)