Skip to main content
Version: v7 Beta
Pro Player Feature

This feature is available exclusively in Pro Player. To access this functionality, please contact us.

Downloading Events

The Offline Video SDK emits events that allow you to monitor and react to changes in download status and progress. You can subscribe to these events using the useEvent hook.

Available Events

onError

Fired when an error occurs during download.

Callback signature:

(error: string) => void

Parameters:

  • error: Error message describing what went wrong
import { useEvent } from "@TheWidlarzGroup/react-native-video-stream-downloader";

useEvent("onError", (error: string) => {
console.error("Download error:", error);
});

onDownloadProgress

Fired periodically during downloads with current progress information.

Callback signature:

(downloads: DownloadStatus[]) => void

Parameters:

import { useEvent } from "@TheWidlarzGroup/react-native-video-stream-downloader";

useEvent("onDownloadProgress", (downloads: DownloadStatus[]) => {
downloads.forEach((download) => {
console.log(`Download ${download.id}: ${(download.progress * 100).toFixed(1)}%`);
});
});

onDownloadEnd

Fired when a download completes (successfully or with failure).

Callback signature:

(download: DownloadStatus) => void

Parameters:

  • download: Final DownloadStatus - See DownloadStatus structure in API Reference for complete properties. When this event fires, status will be either 'completed' or 'failed'.
import { useEvent } from "@TheWidlarzGroup/react-native-video-stream-downloader";

useEvent("onDownloadEnd", (download: DownloadStatus) => {
if (download.status === "completed") {
console.log(`Download ${download.id} completed successfully`);
} else {
console.log(`Download ${download.id} failed`);
}
});

Using Events

Events are automatically typed and can be used with the useEvent hook:

import { useEvent } from "@TheWidlarzGroup/react-native-video-stream-downloader";

function DownloadManager() {
useEvent("onDownloadProgress", (downloads) => {
// Update UI with progress
});

useEvent("onDownloadEnd", (download) => {
// Handle completion
});

useEvent("onError", (error) => {
// Handle errors
});

// ... rest of component
}

The useEvent hook automatically manages cleanup when the component unmounts, preventing memory leaks.