2024-03-08 05:04:27 -07:00
import PlatformsList from '../../components/PlatformsList/PlatformsList.tsx';
2024-03-08 04:48:01 -07:00
2023-10-26 00:54:14 -06:00
# Methods
2024-03-08 04:48:01 -07:00
2023-10-26 00:54:14 -06:00
This page shows the list of available methods
2024-03-08 04:48:01 -07:00
### `dismissFullscreenPlayer`
2023-10-26 00:54:14 -06:00
2024-03-08 04:48:01 -07:00
<PlatformsList types={['Android', 'iOS']} />
2023-10-26 00:54:14 -06:00
`dismissFullscreenPlayer(): Promise<void>`
Take the player out of fullscreen mode.
2024-05-04 06:36:39 -06:00
### `pause`
<PlatformsList types={['Android', 'iOS']} />
`pause(): Promise<void>`
Pause the video.
2023-10-26 00:54:14 -06:00
### `presentFullscreenPlayer`
2024-03-08 04:48:01 -07:00
<PlatformsList types={['Android', 'iOS']} />
2023-10-26 00:54:14 -06:00
`presentFullscreenPlayer(): Promise<void>`
Put the player in fullscreen mode.
On iOS, this displays the video in a fullscreen view controller with controls.
On Android, this puts the navigation controls in fullscreen mode. It is not a complete fullscreen implementation, so you will still need to apply a style that makes the width and height match your screen dimensions to get a fullscreen video.
2024-05-04 06:36:39 -06:00
### `resume`
2024-03-08 04:48:01 -07:00
<PlatformsList types={['Android', 'iOS']} />
2024-05-04 06:36:39 -06:00
`resume(): Promise<void>`
2023-10-26 00:54:14 -06:00
2024-05-04 06:36:39 -06:00
Resume the video.
2023-10-26 00:54:14 -06:00
2024-05-04 06:36:39 -06:00
### `restoreUserInterfaceForPictureInPictureStopCompleted`
2023-10-26 00:54:14 -06:00
2024-05-04 06:36:39 -06:00
<PlatformsList types={['iOS']} />
2023-10-26 00:54:14 -06:00
2024-05-04 06:36:39 -06:00
`restoreUserInterfaceForPictureInPictureStopCompleted(restored)`
2023-10-26 00:54:14 -06:00
2024-05-04 06:36:39 -06:00
This function corresponds to the completion handler in Apple's [restoreUserInterfaceForPictureInPictureStop](https://developer.apple.com/documentation/avkit/avpictureinpicturecontrollerdelegate/1614703-pictureinpicturecontroller?language=objc). IMPORTANT: This function must be called after `onRestoreUserInterfaceForPictureInPictureStop` is called.
2023-10-26 00:54:14 -06:00
2024-03-08 04:48:01 -07:00
### `save`
2023-10-26 00:54:14 -06:00
2024-03-08 04:48:01 -07:00
<PlatformsList types={['iOS']} />
2023-10-26 00:54:14 -06:00
`save(): Promise<{ uri: string }>`
Save video to your Photos with current filter prop. Returns promise.
Notes:
2024-03-08 04:48:01 -07:00
- Currently only supports highest quality export
- Currently only supports MP4 export
- Currently only supports exporting to user's cache directory with a generated UUID filename.
- User will need to remove the saved video through their Photos app
- Works with cached videos as well. (Checkout video-caching example)
- If the video is has not began buffering (e.g. there is no internet connection) then the save function will throw an error.
- If the video is buffering then the save function promise will return after the video has finished buffering and processing.
Future:
2023-10-26 00:54:14 -06:00
2024-03-08 04:48:01 -07:00
- Will support multiple qualities through options
- Will support more formats in the future through options
- Will support custom directory and file name through options
2023-10-26 00:54:14 -06:00
### `seek`
2024-03-08 04:48:01 -07:00
<PlatformsList types={['All']} />
2023-10-26 00:54:14 -06:00
`seek(seconds)`
Seek to the specified position represented by seconds. seconds is a float value.
2024-05-20 07:58:11 -06:00
`seek()` can only be called after the `onLoad` event has fired. Once completed, the [onSeek](./events#onseek) event will be called.
2023-10-26 00:54:14 -06:00
#### Exact seek
2024-03-08 04:48:01 -07:00
<PlatformsList types={['iOS']} />
2023-10-26 00:54:14 -06:00
By default iOS seeks within 100 milliseconds of the target position. If you need more accuracy, you can use the seek with tolerance method:
`seek(seconds, tolerance)`
tolerance is the max distance in milliseconds from the seconds position that's allowed. Using a more exact tolerance can cause seeks to take longer. If you want to seek exactly, set tolerance to 0.
2024-05-20 04:21:48 -06:00
### `setVolume`
<PlatformsList types={['Android', 'iOS']} />
`setVolume(value): Promise<void>`
2024-05-20 07:58:11 -06:00
This function will change the volume exactly like [volume](./props#volume) property. default value and range are the same then.
2024-05-20 04:21:48 -06:00
2024-05-28 03:00:38 -06:00
### `getCurrentPosition`
<PlatformsList types={['Android', 'iOS']} />
`getCurrentPosition(): Promise<number>`
This function retrieves and returns the precise current position of the video playback, measured in seconds.
This function will throw an error if player is not initialized.
2023-10-26 00:54:14 -06:00
### Example Usage
2024-03-08 04:48:01 -07:00
2023-10-26 00:54:14 -06:00
```tsx
const videoRef = useRef<VideoRef>(null);
const someCoolFunctions = async () => {
2024-03-08 04:48:01 -07:00
if (!videoRef.current) {
2023-10-26 00:54:14 -06:00
return;
}
// present or dismiss fullscreen player
videoRef.current.presentFullscreenPlayer();
videoRef.current.dismissFullscreenPlayer();
// pause or play the video
videoRef.current.play();
videoRef.current.pause();
// save video to your Photos with current filter prop
const response = await videoRef.current.save();
const path = response.uri;
// seek to the specified position represented by seconds
videoRef.current.seek(200);
// or on iOS you can seek with tolerance
videoRef.current.seek(200, 10);
};
return (
<Video
ref={videoRef}
2024-03-08 04:48:01 -07:00
source={{uri: 'https://www.w3schools.com/html/mov_bbb.mp4'}}
2023-10-26 00:54:14 -06:00
/>
);
```
## Static methods
### `getWidevineLevel`
2024-03-08 04:48:01 -07:00
<PlatformsList types={['Android']} />
2023-10-26 00:54:14 -06:00
Indicates whether the widevine level supported by device.
Possible values are:
2024-03-08 04:48:01 -07:00
- 0 - unable to determine widevine support (typically not supported)
- 1, 2, 3 - Widevine level supported
2023-10-26 00:54:14 -06:00
### `isCodecSupported`
2024-03-08 04:48:01 -07:00
2024-05-04 06:36:39 -06:00
<PlatformsList types={['Android']} />
2023-10-26 00:54:14 -06:00
Indicates whether the provided codec is supported level supported by device.
parameters:
2024-03-08 04:48:01 -07:00
2023-10-26 00:54:14 -06:00
- `mimetype`: mime type of codec to query
- `width`, `height`: resolution to query
Possible results:
2024-03-08 04:48:01 -07:00
2023-10-26 00:54:14 -06:00
- `hardware` - codec is supported by hardware
- `software` - codec is supported by software only
- `unsupported` - codec is not supported
### `isHEVCSupported`
2024-03-08 04:48:01 -07:00
<PlatformsList types={['Android']} />
2023-10-26 00:54:14 -06:00
2024-05-04 06:36:39 -06:00
Helper which Indicates whether the provided HEVC/1920\*1080 is supported level supported by device. It uses isCodecSupported internally.
2023-10-26 00:54:14 -06:00
### Example Usage
2024-03-08 04:48:01 -07:00
2023-10-26 00:54:14 -06:00
```tsx
import { VideoDecoderProperties } from 'react-native-video';
VideoDecoderProperties.getWidevineLevel().then((level) => {
...
});
VideoDecoderProperties.isCodecSupported('video/hevc', 1920, 1080).then((support) => {
...
});
VideoDecoderProperties.isHEVCSupported().then((support) => {
...
});
2024-03-08 04:48:01 -07:00
```