[Video] Download videos (#4886)

Co-authored-by: Samuel Newman <10959775+mozzius@users.noreply.github.com>
This commit is contained in:
Hailey 2024-08-15 11:23:48 -07:00 committed by GitHub
parent b9975697e2
commit 11061b628e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 747 additions and 3 deletions

View file

@ -0,0 +1,39 @@
import React from 'react'
import {StyleProp, ViewStyle} from 'react-native'
import {requireNativeModule, requireNativeViewManager} from 'expo-modules-core'
import {HLSDownloadViewProps} from './types'
const NativeModule = requireNativeModule('ExpoHLSDownload')
const NativeView: React.ComponentType<
HLSDownloadViewProps & {
ref: React.RefObject<any>
style: StyleProp<ViewStyle>
}
> = requireNativeViewManager('ExpoHLSDownload')
export default class HLSDownloadView extends React.PureComponent<HLSDownloadViewProps> {
private nativeRef: React.RefObject<any> = React.createRef()
constructor(props: HLSDownloadViewProps) {
super(props)
}
static isAvailable(): boolean {
return NativeModule.isAvailable()
}
async startDownloadAsync(sourceUrl: string): Promise<void> {
return await this.nativeRef.current.startDownloadAsync(sourceUrl)
}
render() {
return (
<NativeView
ref={this.nativeRef}
style={{height: 0, width: 0}}
{...this.props}
/>
)
}
}

View file

@ -0,0 +1,22 @@
import React from 'react'
import {NotImplementedError} from '../NotImplemented'
import {HLSDownloadViewProps} from './types'
export default class HLSDownloadView extends React.PureComponent<HLSDownloadViewProps> {
constructor(props: HLSDownloadViewProps) {
super(props)
}
static isAvailable(): boolean {
return false
}
async startDownloadAsync(sourceUrl: string): Promise<void> {
throw new NotImplementedError({sourceUrl})
}
render() {
return null
}
}

View file

@ -0,0 +1,10 @@
import {NativeSyntheticEvent} from 'react-native'
export interface HLSDownloadViewProps {
downloaderUrl: string
onSuccess: (e: NativeSyntheticEvent<{uri: string}>) => void
onStart?: () => void
onError?: (e: NativeSyntheticEvent<{message: string}>) => void
onProgress?: (e: NativeSyntheticEvent<{progress: number}>) => void
}