Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Example/app/jsx/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import SourcesExample from './screens/SourcesExample';
import YoutubeExample from './screens/YoutubeExample';
import PlayerInModal from './screens/PlayerInModal';
import GlobalPlayerExample from './screens/GlobalPlayerExample';
import OfflineDownloadExample from './screens/OfflineDownloadExample';

const Stack = createNativeStackNavigator();

Expand All @@ -40,6 +41,7 @@ export default class App extends Component {
<Stack.Screen name="Modal" component={PlayerInModal} />
<Stack.Screen name="List" component={ListExample} />
<Stack.Screen name="DRM" component={DRMExample} />
<Stack.Screen name="Offline Download" component={OfflineDownloadExample} />
<Stack.Screen name="Local" component={LocalFileExample} />
<Stack.Screen name="Sources" component={SourcesExample} />
<Stack.Screen name="Youtube" component={YoutubeExample} />
Expand Down
103 changes: 103 additions & 0 deletions Example/app/jsx/modules/JWPlayerOffline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* JWPlayerOffline Module
*
* Native module for downloading and playing offline DRM-protected videos
*/

import { NativeModules, NativeEventEmitter } from 'react-native';

const JWPlayerOfflineModule = NativeModules.RNJWPlayerOfflineModule;

export interface OfflineVideoConfig {
mediaId: string;
file: string;
processSpcUrl?: string;
certificateUrl?: string;
}

export interface OfflinePlaylistItem {
mediaId: string;
file: string;
localURL: string;
}

export interface DownloadProgressEvent {
mediaId: string;
progress: number;
}

export interface DownloadCompleteEvent {
mediaId: string;
url: string;
}

export interface DownloadErrorEvent {
mediaId: string;
error: string;
}

class JWPlayerOffline {
private eventEmitter: NativeEventEmitter;

constructor() {
this.eventEmitter = new NativeEventEmitter(JWPlayerOfflineModule);
}

/**
* Start downloading a video for offline playback
*/
downloadVideo(config: OfflineVideoConfig): Promise<boolean> {
return JWPlayerOfflineModule.downloadVideo(config);
}

/**
* Check if a video is already downloaded
*/
isDownloaded(mediaId: string): Promise<boolean> {
return JWPlayerOfflineModule.isDownloaded(mediaId);
}

/**
* Get list of all downloaded videos
*/
getDownloads(): Promise<Array<{ mediaId: string }>> {
return JWPlayerOfflineModule.getDownloads();
}

/**
* Delete a downloaded video
*/
deleteDownload(mediaId: string): Promise<boolean> {
return JWPlayerOfflineModule.deleteDownload(mediaId);
}

/**
* Get the playlist item for offline playback
*/
getOfflinePlaylistItem(mediaId: string): Promise<OfflinePlaylistItem> {
return JWPlayerOfflineModule.getOfflinePlaylistItem(mediaId);
}

/**
* Listen for download progress events
*/
onDownloadProgress(callback: (event: DownloadProgressEvent) => void) {
return this.eventEmitter.addListener('onDownloadProgress', callback);
}

/**
* Listen for download complete events
*/
onDownloadComplete(callback: (event: DownloadCompleteEvent) => void) {
return this.eventEmitter.addListener('onDownloadComplete', callback);
}

/**
* Listen for download error events
*/
onDownloadError(callback: (event: DownloadErrorEvent) => void) {
return this.eventEmitter.addListener('onDownloadError', callback);
}
}

export default new JWPlayerOffline();
2 changes: 1 addition & 1 deletion Example/app/jsx/screens/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Icons from 'react-native-vector-icons/FontAwesome5';
import {useNavigation} from '@react-navigation/native';
import {useSafeAreaInsets} from 'react-native-safe-area-context';

const SCREENS = ['TypeScript Example', 'Single', 'On Before Next Playlist Item', 'Modal', 'List', 'DRM', 'Local', 'Sources', 'Youtube', 'Global Player'];
const SCREENS = ['TypeScript Example', 'Single', 'On Before Next Playlist Item', 'Modal', 'List', 'DRM', 'Offline Download', 'Local', 'Sources', 'Youtube', 'Global Player'];

export default () => {
const navigation = useNavigation();
Expand Down
Loading