UNPKG

@zezosoft/zezo-ott-react-native-video-player

Version:

Production-ready React Native OTT video player library for Android & iOS. Features: playlists, seasons, auto-next playback, subtitles (SRT/VTT), custom theming, analytics tracking, fullscreen mode, gesture controls, ads player (pre-roll/mid-roll/post-roll

60 lines (57 loc) 1.83 kB
"use strict"; import { useCallback } from 'react'; import { useAdsPlayerStore } from "../store/adsPlayerStore.js"; import { useVideoPlayerStore } from "../../VideoPlayer/store/videoPlayerStore.js"; import { handlePause } from "../../VideoPlayer/utils/index.js"; /** * Reusable hook for initializing and starting ads * Consolidates duplicate ad initialization logic from useAdsManager */ export const useAdInitialization = ({ onAdTracking } = {}) => { const { setCurrentAd, setIsAdPlaying, setIsAdPaused, setResumeTime } = useAdsPlayerStore(); const { setIsPaused } = useVideoPlayerStore(); const startAd = useCallback((ad, options = {}) => { try { // Always pause main video first before starting ad // Use handlePause to properly pause video and save watch time handlePause(); setIsPaused(true); // Set ad state - ensure ad is ready to play setCurrentAd(ad); setIsAdPlaying(true); setIsAdPaused(false); if (options.resumeTime !== undefined) { setResumeTime(options.resumeTime); } // Track impression is handled in AdsPlayer component to avoid duplication // Only track here if explicitly requested if (options.trackImpression === true && ad.tracking?.impression && onAdTracking) { onAdTracking({ ad, trackingUrl: ad.tracking.impression, event: 'impression' }); } } catch (error) { console.error('Error starting ad:', error); // Reset state on error setCurrentAd(null); setIsAdPlaying(false); setIsAdPaused(false); throw error; } }, [setCurrentAd, setIsAdPlaying, setIsAdPaused, setIsPaused, setResumeTime, onAdTracking]); return { startAd }; }; //# sourceMappingURL=useAdInitialization.js.map