@@ -4,6 +4,7 @@ import { DOMEvent, isNil, listenEvent, useDisposalBin } from 'maverick.js/std';
44import type { MediaContext } from '../../core/api/media-context' ;
55import type { MediaCanPlayDetail } from '../../core/api/media-events' ;
66import type { MediaErrorCode } from '../../core/api/types' ;
7+ import { PageVisibility } from '../../foundation/observers/page-visibility' ;
78import { RAFLoop } from '../../foundation/observers/raf-loop' ;
89import { isHLSSrc } from '../../utils/mime' ;
910import { getNumberOfDecimalPlaces } from '../../utils/number' ;
@@ -16,6 +17,7 @@ export class HTMLMediaEvents {
1617 private _attachedLoadStart = false ;
1718 private _attachedCanPlay = false ;
1819 private _timeRAF = new RAFLoop ( this . _onAnimationFrame . bind ( this ) ) ;
20+ private _pageVisibility = new PageVisibility ( ) ;
1921
2022 private get _media ( ) {
2123 return this . _provider . media ;
@@ -30,7 +32,10 @@ export class HTMLMediaEvents {
3032 private _ctx : MediaContext ,
3133 ) {
3234 this . _attachInitialListeners ( ) ;
35+
36+ this . _pageVisibility . connect ( ) ;
3337 effect ( this . _attachTimeUpdate . bind ( this ) ) ;
38+
3439 onDispose ( this . _onDispose . bind ( this ) ) ;
3540 }
3641
@@ -253,12 +258,17 @@ export class HTMLMediaEvents {
253258 }
254259
255260 protected _attachTimeUpdate ( ) {
256- if ( this . _ctx . $state . paused ( ) ) {
261+ const isPaused = this . _ctx . $state . paused ( ) ,
262+ isPageHidden = this . _pageVisibility . visibility === 'hidden' ,
263+ shouldListenToTimeUpdates = isPaused || isPageHidden ;
264+
265+ if ( shouldListenToTimeUpdates ) {
257266 listenEvent ( this . _media , 'timeupdate' , this . _onTimeUpdate . bind ( this ) ) ;
258267 }
259268 }
260269
261270 protected _onTimeUpdate ( event : Event ) {
271+ console . log ( this . _media . currentTime ) ;
262272 this . _updateCurrentTime ( this . _media . currentTime , event ) ;
263273 }
264274
0 commit comments