import { VideoJsPlayer } from 'video.js' ; import Player from '../index' ; function initializeEventListeners ( player , props ) { let currentTimeSecond = 0 ; let previousTimeSecond = 0 ; let startPositionSecond = 0 ; player . on ( 'play' , ( event ) => { props . onPlay && props . onPlay ( event , player , player . currentTime ( ) ) ; } ) ; player . on ( 'pause' , ( event ) => { props . onPause && props . onPause ( event , player , player . currentTime ( ) ) ; } ) ; player . on ( 'waiting' , ( event ) => { props . onWaiting && props . onWaiting ( event , player , player . currentTime ( ) ) ; } ) ; player . on ( 'playing' , ( event ) => { props . onPlaying && props . onPlaying ( event , player , player . currentTime ( ) ) ; } ) ; player . on ( 'timeupdate' , ( event ) => { let temp = player . currentTime ( ) ; props . onTimeUpdate && props . onTimeUpdate ( event , player , temp ) ; previousTimeSecond = currentTimeSecond ; currentTimeSecond = temp ; if ( previousTimeSecond < currentTimeSecond ) { startPositionSecond = previousTimeSecond ; previousTimeSecond = currentTimeSecond ; } } ) ; player . on ( 'seeking' , ( event ) => { player . off ( 'timeupdate' , ( ) => { } ) ; player . one ( 'seeked' , ( ) => { } ) ; props . onSeeking && props . onSeeking ( event , player , player . currentTime ( ) ) ; } ) ; player . on ( 'seeked' , ( event ) => { const completeTimeSecond = player . currentTime ( ) ; props . onSeeked && props . onSeeked ( event , player , startPositionSecond , completeTimeSecond ) ; } ) ; player . on ( 'ended' , ( event ) => { props . onEnded && props . onEnded ( event , player ) ; } ) ; player . on ( 'error' , ( event ) => { props . onError && props . onError ( event , player ) ; } ) ; player . on ( 'loadeddata' , ( event ) => { props . onLoadedData && props . onLoadedData ( event , player ) ; } ) ; player . on ( 'loadedmetadata' , ( event ) => { props . onLoadedMetadata && props . onLoadedMetadata ( event , player ) ; } ) ; } export default initializeEventListeners ;