Skip to content

Commit

Permalink
[expo-video] Add expo-video docs page (#27854)
Browse files Browse the repository at this point in the history
# Why

Expo-video is missing a docs page.

ENG-11349

# How

Renamed the `video.mdx` to `video-av.mdx` and assigned `video.mdx` as
`expo-video` docs page. We should consider doing this the other way
around (adding a suffix to `expo-video` file). Current way might create
issues with linking to the docs, eg. if someone wants to redirect people
to the latest `expo-av` video docs so they would link to
`https://docs.expo.dev/versions/latest/sdk/video/`, but the users will
be redirected to `expo-video` docs after SDK 51. I kept it this way in
case we believe people should be redirected to `expo-video` anyways. Let
me know what you think about it :)

Created a simple example for `expo-video` (similar to the `expo-av`
example), which showcases how to use player properties and events.

# Test Plan

Tested by running the docs locally
  • Loading branch information
behenate committed Mar 27, 2024
1 parent 3d009bf commit e4c1352
Show file tree
Hide file tree
Showing 25 changed files with 240 additions and 102 deletions.
1 change: 1 addition & 0 deletions docs/components/plugins/api/APISectionUtils.tsx
Expand Up @@ -123,6 +123,7 @@ const nonLinkableTypes = [
'NativeSyntheticEvent',
'ParsedQs',
'ServiceActionResult',
'SharedObject',
'T',
'TaskOptions',
'Uint8Array',
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/versions/unversioned/sdk/av.mdx
Expand Up @@ -16,7 +16,7 @@ import {
} from '~/components/plugins/ConfigSection';
import { AndroidPermissions, IOSPermissions } from '~/components/plugins/permissions';

The [`Audio.Sound`](audio.mdx) objects and [`Video`](video.mdx) components share a unified imperative API for media playback.
The [`Audio.Sound`](audio.mdx) objects and [`Video`](video-av.mdx) components share a unified imperative API for media playback.

Note that for `Video`, all of the operations are also available via props on the component. However, we recommend using this imperative playback API for most applications where finer control over the state of the video playback is needed.

Expand Down Expand Up @@ -108,7 +108,7 @@ render() {
}
```

See the [video documentation](video.mdx) for further information.
See the [video documentation](video-av.mdx) for further information.

### Example: `setOnPlaybackStatusUpdate()`

Expand Down
98 changes: 98 additions & 0 deletions docs/pages/versions/unversioned/sdk/video-av.mdx
@@ -0,0 +1,98 @@
---
title: Video (expo-av)
description: A library that provides an API to implement video playback and recording in apps.
sourceCodeUrl: 'https://github.com/expo/expo/tree/main/packages/expo-av'
packageName: 'expo-av'
iconUrl: '/static/images/packages/expo-av.png'
platforms: ['android', 'ios', 'web']
---

import APISection from '~/components/plugins/APISection';
import { APIInstallSection } from '~/components/plugins/InstallSection';
import { SnackInline } from '~/ui/components/Snippet';

> **info** The `Video` component from expo-av, which is documented on this page, will be replaced by an improved version in `expo-video` in an upcoming release when the new library is stable. [Learn about `expo-video`](video.mdx).
The `Video` component from `expo-av` displays a video inline with the other UI elements in your app.

Much of Video and Audio have common APIs that are documented in [AV documentation](av.mdx). This page covers video-specific props and APIs. We encourage you to skim through this document to get basic video working, and then move on to [AV documentation](av.mdx) for more advanced functionality. The audio experience of video (such as whether to interrupt music already playing in another app, or whether to play sound while the phone is on silent mode) can be customized using the [Audio API](audio.mdx).

## Installation

<APIInstallSection />

## Usage

Here's a simple example of a video with a play/pause button.

<SnackInline label='Video' dependencies={['expo-av', 'expo-asset']}>

```jsx
import * as React from 'react';
import { View, StyleSheet, Button } from 'react-native';
import { Video, ResizeMode } from 'expo-av';

export default function App() {
const video = React.useRef(null);
const [status, setStatus] = React.useState({});
return (
<View style={styles.container}>
<Video
ref={video}
style={styles.video}
source={{
uri: 'https://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4',
}}
useNativeControls
resizeMode={ResizeMode.CONTAIN}
isLooping
onPlaybackStatusUpdate={status => setStatus(() => status)}
/>
<View style={styles.buttons}>
<Button
title={status.isPlaying ? 'Pause' : 'Play'}
onPress={() =>
status.isPlaying ? video.current.pauseAsync() : video.current.playAsync()
}
/>
</View>
</View>
);
}

/* @hide const styles = StyleSheet.create({ ... }); */
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
backgroundColor: '#ecf0f1',
},
video: {
alignSelf: 'center',
width: 320,
height: 200,
},
buttons: {
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
},
});
/* @end */
```

</SnackInline>

For more advanced examples, check out the [Playlist example](https://github.com/expo/playlist-example/blob/master/App.js), and the [custom `VideoPlayer` controls component](https://github.com/ihmpavel/expo-video-player/blob/master/lib/index.tsx) that wraps `<Video>`, adds custom controls and use the `<Video>` API extensively. The `VideoPlayer` controls is used in [this app](https://github.com/expo/harvard-cs50-app).

## API

```js
import { Video } from 'expo-av';
```

<APISection packageName="expo-video-av" apiName="Video(expo-av)" strictTypes />

## Unified API

The rest of the API on the `Video` component `ref` is the same as the API for `Audio.Sound` - see the [AV documentation](av/#playback) for further information.
101 changes: 56 additions & 45 deletions docs/pages/versions/unversioned/sdk/video.mdx
@@ -1,94 +1,105 @@
---
title: Video
description: A library that provides an API to implement video playback and recording in apps.
sourceCodeUrl: 'https://github.com/expo/expo/tree/main/packages/expo-av'
packageName: 'expo-av'
iconUrl: '/static/images/packages/expo-av.png'
description: A library that provides an API to implement video playback in apps.
sourceCodeUrl: 'https://github.com/expo/expo/tree/main/packages/expo-video'
packageName: 'expo-video'
platforms: ['android', 'ios', 'web']
---

import APISection from '~/components/plugins/APISection';
import { APIInstallSection } from '~/components/plugins/InstallSection';
import { SnackInline } from '~/ui/components/Snippet';

The `Video` component from **`expo-av`** displays a video inline with the other UI elements in your app.
> **info** `expo-video` is a new, experimental library that aims to replace the `Video` component from `expo-av` with a more modern and reliable implementation. If you are looking for a more stable API, use [`expo-av`](video.mdx) until this library has stabilized.
Much of Video and Audio have common APIs that are documented in [AV documentation](av.mdx). This page covers video-specific props and APIs. We encourage you to skim through this document to get basic video working, and then move on to [AV documentation](av.mdx) for more advanced functionality. The audio experience of video (such as whether to interrupt music already playing in another app, or whether to play sound while the phone is on silent mode) can be customized using the [Audio API](audio.mdx).
`expo-video` is a cross-platform, performant video component for React Native and Expo with Web support.

## Installation

<APIInstallSection />

## Usage

Here's a simple example of a video with a play/pause button.
Here's a simple example of a video with a play and pause button.

<SnackInline label='Video' dependencies={['expo-av', 'expo-asset']}>
<SnackInline label='Video' dependencies={['expo-video']}>

```jsx
import * as React from 'react';
import { View, StyleSheet, Button } from 'react-native';
import { Video, ResizeMode } from 'expo-av';
import { useVideoPlayer, VideoView } from 'expo-video';
import { useEffect, useRef, useState } from 'react';
import { PixelRatio, StyleSheet, View, Button } from 'react-native';

const videoSource =
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4';

export default function VideoScreen() {
const ref = useRef(null);
const [isPlaying, setIsPlaying] = useState(true);
const player = useVideoPlayer(videoSource, (player) => {
player.loop = true;
player.play();
});

useEffect(() => {
const subscription = player.addListener('playingChange', (isPlaying) => {
setIsPlaying(isPlaying);
});

return () => {
subscription.remove();
};
}, [player]);

export default function App() {
const video = React.useRef(null);
const [status, setStatus] = React.useState({});
return (
<View style={styles.container}>
<Video
ref={video}
<View style={styles.contentContainer}>
<VideoView
ref={ref}
style={styles.video}
source={{
uri: 'https://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4',
}}
useNativeControls
resizeMode={ResizeMode.CONTAIN}
isLooping
onPlaybackStatusUpdate={status => setStatus(() => status)}
player={player}
allowsFullscreen
allowsPictureInPicture
/>
<View style={styles.buttons}>
<View style={styles.controlsContainer}>
<Button
title={status.isPlaying ? 'Pause' : 'Play'}
onPress={() =>
status.isPlaying ? video.current.pauseAsync() : video.current.playAsync()
}
title={isPlaying ? 'Pause' : 'Play'}
onPress={() => {
if (isPlaying) {
player.pause();
} else {
player.play();
}
setIsPlaying(!isPlaying);
}}
/>
</View>
</View>
);
}

const styles = StyleSheet.create({
container: {
contentContainer: {
flex: 1,
padding: 10,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#ecf0f1',
paddingHorizontal: 50,
},
video: {
alignSelf: 'center',
width: 320,
height: 200,
width: 350,
height: 275,
},
buttons: {
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
controlsContainer: {
padding: 10,
},
});
```

</SnackInline>

For more advanced examples, check out the [Playlist example](https://github.com/expo/playlist-example/blob/master/App.js), and the [custom `VideoPlayer` controls component](https://github.com/ihmpavel/expo-video-player/blob/master/lib/index.tsx) that wraps `<Video>`, adds custom controls and use the `<Video>` API extensively. The `VideoPlayer` controls is used in [this app](https://github.com/expo/harvard-cs50-app).

## API

```js
import { Video } from 'expo-av';
import { VideoView, useVideoPlayer } from 'expo-video';
```

<APISection packageName="expo-video" apiName="Video" strictTypes />

## Unified API

The rest of the API on the `Video` component `ref` is the same as the API for `Audio.Sound` - see the [AV documentation](av/#playback) for further information.
1 change: 1 addition & 0 deletions docs/public/static/data/unversioned/expo-video-av.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/public/static/data/unversioned/expo-video.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/expo-video/CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@

### 🎉 New features

- Create a docs page. ([#27854](https://github.com/expo/expo/pull/27854) by [@behenate](https://github.com/behenate))
- Add support for events on Android and iOS. ([#27632](https://github.com/expo/expo/pull/27632) by [@behenate](https://github.com/behenate))
- Add support for `loop`, `playbackRate`, `preservesPitch` and `currentTime` properties. ([#27367](https://github.com/expo/expo/pull/27367) by [@behenate](https://github.com/behenate))
- Add background playback support. ([#27110](https://github.com/expo/expo/pull/27110) by [@behenate](https://github.com/behenate))
Expand Down
16 changes: 13 additions & 3 deletions packages/expo-video/build/VideoView.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-video/build/VideoView.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions packages/expo-video/build/VideoView.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e4c1352

Please sign in to comment.