UNPKG

react-native-theoplayer

Version:

A THEOplayer video component for react-native.

29 lines (27 loc) 881 B
"use strict"; import { CachingTaskEventType } from 'react-native-theoplayer'; import { useEffect, useState } from 'react'; /** * A convenience hook that keeps the progress value of a caching task. * * @category Caching * @public */ export const useCachingTaskProgress = (task, debug = true) => { const [progress, setProgress] = useState(task.percentageCached); useEffect(() => { const onProgress = () => { const percentageCached = task.percentageCached; if (debug) { console.log('[MediaCache] progress change', percentageCached); } setProgress(percentageCached); }; task.addEventListener(CachingTaskEventType.progress, onProgress); return () => { task.removeEventListener(CachingTaskEventType.progress, onProgress); }; }, [task, debug]); return progress; }; //# sourceMappingURL=useCachingTaskProgress.js.map