Skip to content

Commit 8b3845a

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 6e203d0 + cfc7da2 commit 8b3845a

File tree

15 files changed

+269
-100
lines changed

15 files changed

+269
-100
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Changelog
2+
3+
Upcoming release
4+
* Remove ExoPlayer onMetadata that wasn't being used (https://github.com/react-native-community/react-native-video/pull/1040)
5+
* Fix bug where setting the progress interval on iOS didn't work (https://github.com/react-native-community/react-native-video/pull/800)
6+
* Support setting the poster resize mode (https://github.com/react-native-community/react-native-video/pull/595)

README.md

+74-68
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,27 @@ A `<Video>` component for react-native, as seen in
55

66
Requires react-native >= 0.40.0, for RN support of 0.19.0 - 0.39.0 please use a pre 1.0 version.
77

8-
### Add it to your project
8+
## TOC
99

10-
Run `npm i -S react-native-video`
10+
* [Installation](#installation)
11+
* [Usage](#usage)
1112

12-
#### iOS
13+
## Installation
14+
15+
Using npm:
16+
17+
```shell
18+
npm install --save react-native-video
19+
```
20+
21+
or using yarn:
22+
23+
```shell
24+
yarn add react-native-video
25+
```
26+
27+
<details>
28+
<summary>iOS</summary>
1329

1430
Run `react-native link` to link the react-native-video library.
1531

@@ -28,9 +44,11 @@ If you would like to allow other apps to play music over your video component, a
2844
}
2945
```
3046
Note: you can also use the `ignoreSilentSwitch` prop, shown below.
47+
</details>
3148

32-
#### tvOS
33-
49+
<details>
50+
<summary>tvOS</summary>
51+
3452
Run `react-native link` to link the react-native-video library.
3553

3654
`react-native link` don’t works properly with the tvOS target so we need to add the library manually.
@@ -50,22 +68,32 @@ Scroll to « Linked Frameworks and Libraries » and tap on the + button
5068
Select RCTVideo-tvOS
5169

5270
<img src="./docs/tvOS-step-4.jpg" width="40%">
71+
</details>
5372

54-
That’s all, you can use react-native-video for your tvOS application
55-
56-
#### Android
73+
<details>
74+
<summary>Android</summary>
5775

5876
Run `react-native link` to link the react-native-video library.
5977

6078
Or if you have trouble, make the following additions to the given files manually:
6179

6280
**android/settings.gradle**
6381

82+
The newer ExoPlayer library will work for most people.
83+
84+
```gradle
85+
include ':react-native-video'
86+
project(':react-native-video').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-video/android-exoplayer')
87+
```
88+
89+
If you need to use the old Android media player based player, use the following instead:
90+
6491
```gradle
6592
include ':react-native-video'
6693
project(':react-native-video').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-video/android')
6794
```
6895

96+
6997
**android/app/build.gradle**
7098

7199
```gradle
@@ -94,8 +122,10 @@ protected List<ReactPackage> getPackages() {
94122
);
95123
}
96124
```
125+
</details>
97126

98-
#### Windows
127+
<details>
128+
<summary>Windows</summary>
99129

100130
Make the following additions to the given files manually:
101131

@@ -104,19 +134,17 @@ Make the following additions to the given files manually:
104134
Add the `ReactNativeVideo` project to your solution.
105135

106136
1. Open the solution in Visual Studio 2015
107-
2. Right-click Solution icon in Solution Explorer > Add > Existing Project...
108-
3.
109-
UWP: Select `node_modules\react-native-video\windows\ReactNativeVideo\ReactNativeVideo.csproj`
110-
WPF: Select `node_modules\react-native-video\windows\ReactNativeVideo.Net46\ReactNativeVideo.Net46.csproj`
137+
2. Right-click Solution icon in Solution Explorer > Add > Existing Project
138+
* UWP: Select `node_modules\react-native-video\windows\ReactNativeVideo\ReactNativeVideo.csproj`
139+
* WPF: Select `node_modules\react-native-video\windows\ReactNativeVideo.Net46\ReactNativeVideo.Net46.csproj`
111140

112141
**windows/myapp/myapp.csproj**
113142

114143
Add a reference to `ReactNativeVideo` to your main application project. From Visual Studio 2015:
115144

116145
1. Right-click main application project > Add > Reference...
117-
2.
118-
UWP: Check `ReactNativeVideo` from Solution Projects.
119-
WPF: Check `ReactNativeVideo.Net46` from Solution Projects.
146+
* UWP: Check `ReactNativeVideo` from Solution Projects.
147+
* WPF: Check `ReactNativeVideo.Net46` from Solution Projects.
120148

121149
**MainPage.cs**
122150

@@ -143,6 +171,7 @@ using System.Collections.Generic;
143171

144172
...
145173
```
174+
</details>
146175

147176
## Usage
148177

@@ -153,31 +182,39 @@ using System.Collections.Generic;
153182

154183
<Video source={{uri: "background"}} // Can be a URL or a local file.
155184
poster="https://baconmockup.com/300/200/" // uri to an image to display until the video plays
185+
posterResizeMode="contain" // Poster resize mode. One of contain (default), cover, stretch, center, repeat
156186
ref={(ref) => {
157187
this.player = ref
158188
}} // Store reference
159189
rate={1.0} // 0 is paused, 1 is normal.
160190
volume={1.0} // 0 is muted, 1 is normal.
161-
muted={false} // Mutes the audio entirely.
162-
paused={false} // Pauses playback entirely.
191+
muted={true|false} // Mutes the audio entirely. Default false
192+
paused={true|false} // Pauses playback entirely. Default false
163193
resizeMode="cover" // Fill the whole screen at aspect ratio.*
164-
repeat={true} // Repeat forever.
165-
playInBackground={false} // Audio continues to play when app entering background.
166-
playWhenInactive={false} // [iOS] Video continues to play when control or notification center are shown.
194+
repeat={true|false} // Repeat forever. Default false
195+
playInBackground={true|false} // Audio continues to play when app entering background. Default false
196+
playWhenInactive={true|false} // [iOS] Video continues to play when control or notification center are shown. Default false
167197
ignoreSilentSwitch={"ignore"} // [iOS] ignore | obey - When 'ignore', audio will still play with the iOS hard silent switch set to silent. When 'obey', audio will toggle with the switch. When not specified, will inherit audio settings as usual.
168198
progressUpdateInterval={250.0} // [iOS] Interval to fire onProgress (default to ~250ms)
199+
onBuffer={this.onBuffer} // Callback when remote video is buffering
200+
onEnd={this.onEnd} // Callback when playback finishes
201+
onError={this.videoError} // Callback when video cannot be loaded
202+
onFullscreenPlayerWillPresent={this.fullScreenPlayerWillPresent} // Callback before fullscreen starts
203+
onFullscreenPlayerDidPresent={this.fullScreenPlayerDidPresent} // Callback after fullscreen started
204+
onFullscreenPlayerWillDismiss={this.fullScreenPlayerWillDismiss} // Callback before fullscreen stops
205+
onFullscreenPlayerDidDismiss={this.fullScreenPlayerDidDissmiss} // Callback after fullscreen stopped
169206
onLoadStart={this.loadStart} // Callback when video starts to load
170207
onLoad={this.setDuration} // Callback when video loads
171208
onProgress={this.setTime} // Callback every ~250ms with currentTime
172-
onEnd={this.onEnd} // Callback when playback finishes
173-
onError={this.videoError} // Callback when video cannot be loaded
174-
onBuffer={this.onBuffer} // Callback when remote video is buffering
175209
onTimedMetadata={this.onTimedMetadata} // Callback when the stream receive some metadata
176210
style={styles.backgroundVideo} />
177211

178212
// Later to trigger fullscreen
179213
this.player.presentFullscreenPlayer()
180214

215+
// Disable fullscreen
216+
this.player.dismissFullscreenPlayer()
217+
181218
// To set video position in seconds (seek)
182219
this.player.seek(0)
183220

@@ -192,70 +229,39 @@ var styles = StyleSheet.create({
192229
},
193230
});
194231
```
232+
To see the full list of available props, you can check the [propTypes](https://github.com/react-native-community/react-native-video/blob/master/Video.js#L246) of the Video.js component.
195233

196-
- * *For iOS you also need to specify muted for this to work*
234+
- By default, iOS 9+ will only load encrypted HTTPS urls. If you need to load content from a webserver that only supports HTTP, you will need to modify your Info.plist file and add the following entry:
197235

198-
To see full list of available props, you can check [the propTypes](https://github.com/react-native-community/react-native-video/blob/master/Video.js#L246) of the Video.js component.
236+
<img src="./docs/AppTransportSecuritySetting.png" width="50%">
199237

200-
## Android Expansion File Usage
238+
For more detailed info check this [article](https://cocoacasts.com/how-to-add-app-transport-security-exception-domains)
239+
</details>
201240

202-
```javascript
203-
// Within your render function, assuming you have a file called
204-
// "background.mp4" in your expansion file. Just add your main and (if applicable) patch version
205-
<Video source={{uri: "background", mainVer: 1, patchVer: 0}} // Looks for .mp4 file (background.mp4) in the given expansion version.
206-
poster="https://baconmockup.com/300/200/" // uri to an image to display until the video plays
207-
rate={1.0} // 0 is paused, 1 is normal.
208-
volume={1.0} // 0 is muted, 1 is normal.
209-
muted={false} // Mutes the audio entirely.
210-
paused={false} // Pauses playback entirely.
211-
resizeMode="cover" // Fill the whole screen at aspect ratio.
212-
repeat={true} // Repeat forever.
213-
onLoadStart={this.loadStart} // Callback when video starts to load
214-
onLoad={this.setDuration} // Callback when video loads
215-
onProgress={this.setTime} // Callback every ~250ms with currentTime
216-
onEnd={this.onEnd} // Callback when playback finishes
217-
onError={this.videoError} // Callback when video cannot be loaded
218-
style={styles.backgroundVideo} />
219-
220-
// Later on in your styles..
221-
var styles = Stylesheet.create({
222-
backgroundVideo: {
223-
position: 'absolute',
224-
top: 0,
225-
left: 0,
226-
bottom: 0,
227-
right: 0,
228-
},
229-
});
241+
### Android Expansion File Usage
242+
Within your render function, assuming you have a file called
243+
"background.mp4" in your expansion file. Just add your main and (if applicable) patch version
244+
```
245+
<Video
246+
source={{uri: "background", mainVer: 1, patchVer: 0}}
247+
/>
230248
```
249+
This will look for an .mp4 file (background.mp4) in the given expansion version.
231250

232251
### Load files with the RN Asset System
233252

234253
The asset system [introduced in RN `0.14`](http://www.reactnative.com/react-native-v0-14-0-released/) allows loading image resources shared across iOS and Android without touching native code. As of RN `0.31` [the same is true](https://github.com/facebook/react-native/commit/91ff6868a554c4930fd5fda6ba8044dbd56c8374) of mp4 video assets for Android. As of [RN `0.33`](https://github.com/facebook/react-native/releases/tag/v0.33.0) iOS is also supported. Requires `[email protected]`.
235254

236255
```
237256
<Video
238-
repeat
239-
resizeMode='cover'
240257
source={require('../assets/video/turntable.mp4')}
241-
style={styles.backgroundVideo}
242258
/>
243259
```
244260

245261
### Play in background on iOS
246262

247263
To enable audio to play in background on iOS the audio session needs to be set to `AVAudioSessionCategoryPlayback`. See [Apple documentation][3] for additional details. (NOTE: there is now a ticket to [expose this as a prop]( https://github.com/react-native-community/react-native-video/issues/310) )
248264

249-
## Static Methods
250-
251-
`seek(seconds)`
252-
253-
Seeks the video to the specified time (in seconds). Access using a ref to the component
254-
255-
`presentFullscreenPlayer()`
256-
257-
Toggles a fullscreen player. Access using a ref to the component.
258-
259265
## Examples
260266

261267
- See an [Example integration][1] in `react-native-login` *note that this example uses an older version of this library, before we used `export default` -- if you use `require` you will need to do `require('react-native-video').default` as per instructions above.*

Video.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export default class Video extends Component {
218218
top: 0,
219219
right: 0,
220220
bottom: 0,
221-
resizeMode: 'contain',
221+
resizeMode: this.props.posterResizeMode || 'contain'
222222
};
223223

224224
return (
@@ -272,6 +272,7 @@ Video.propTypes = {
272272
]),
273273
resizeMode: PropTypes.string,
274274
poster: PropTypes.string,
275+
posterResizeMode: Image.propTypes.resizeMode,
275276
repeat: PropTypes.bool,
276277
paused: PropTypes.bool,
277278
muted: PropTypes.bool,

android-exoplayer/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ android {
1212

1313
dependencies {
1414
provided 'com.facebook.react:react-native:+'
15-
compile 'com.google.android.exoplayer:exoplayer:r2.4.0'
16-
compile('com.google.android.exoplayer:extension-okhttp:r2.4.0') {
15+
compile 'com.google.android.exoplayer:exoplayer:2.7.3'
16+
compile('com.google.android.exoplayer:extension-okhttp:2.7.3') {
1717
exclude group: 'com.squareup.okhttp3', module: 'okhttp'
1818
}
19-
compile 'com.squareup.okhttp3:okhttp:3.4.2'
19+
compile 'com.squareup.okhttp3:okhttp:3.9.1'
2020
}

android-exoplayer/src/main/java/com/brentvatne/exoplayer/ExoPlayerView.java

+16-9
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@
1818
import com.google.android.exoplayer2.PlaybackParameters;
1919
import com.google.android.exoplayer2.SimpleExoPlayer;
2020
import com.google.android.exoplayer2.Timeline;
21-
import com.google.android.exoplayer2.metadata.Metadata;
22-
import com.google.android.exoplayer2.metadata.MetadataRenderer;
2321
import com.google.android.exoplayer2.source.TrackGroupArray;
2422
import com.google.android.exoplayer2.text.Cue;
2523
import com.google.android.exoplayer2.text.TextRenderer;
2624
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
2725
import com.google.android.exoplayer2.ui.SubtitleView;
2826

2927
import java.util.List;
28+
import java.lang.Object;
3029

3130
@TargetApi(16)
3231
public final class ExoPlayerView extends FrameLayout {
@@ -100,7 +99,6 @@ public void setPlayer(SimpleExoPlayer player) {
10099
this.player.setVideoListener(null);
101100
this.player.removeListener(componentListener);
102101
this.player.setVideoSurface(null);
103-
this.player.setMetadataOutput(componentListener);
104102
}
105103
this.player = player;
106104
shutterView.setVisibility(VISIBLE);
@@ -113,7 +111,6 @@ public void setPlayer(SimpleExoPlayer player) {
113111
player.setVideoListener(componentListener);
114112
player.addListener(componentListener);
115113
player.setTextOutput(componentListener);
116-
player.setMetadataOutput(componentListener);
117114
}
118115
}
119116

@@ -167,7 +164,7 @@ private void updateForCurrentTrackSelections() {
167164
}
168165

169166
private final class ComponentListener implements SimpleExoPlayer.VideoListener,
170-
TextRenderer.Output, ExoPlayer.EventListener, MetadataRenderer.Output {
167+
TextRenderer.Output, ExoPlayer.EventListener {
171168

172169
// TextRenderer.Output implementation
173170

@@ -212,12 +209,12 @@ public void onPlayerError(ExoPlaybackException e) {
212209
}
213210

214211
@Override
215-
public void onPositionDiscontinuity() {
212+
public void onPositionDiscontinuity(int reason) {
216213
// Do nothing.
217214
}
218215

219216
@Override
220-
public void onTimelineChanged(Timeline timeline, Object manifest) {
217+
public void onTimelineChanged(Timeline timeline, Object manifest, int reason) {
221218
// Do nothing.
222219
}
223220

@@ -232,8 +229,18 @@ public void onPlaybackParametersChanged(PlaybackParameters params) {
232229
}
233230

234231
@Override
235-
public void onMetadata(Metadata metadata) {
236-
Log.d("onMetadata", "onMetadata");
232+
public void onSeekProcessed() {
233+
// Do nothing.
234+
}
235+
236+
@Override
237+
public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) {
238+
// Do nothing.
239+
}
240+
241+
@Override
242+
public void onRepeatModeChanged(int repeatMode) {
243+
// Do nothing.
237244
}
238245
}
239246

0 commit comments

Comments
 (0)