Merge branch 'master' into master
This commit is contained in:
commit
5336d4f866
@ -1 +0,0 @@
|
||||
/examples
|
@ -2,10 +2,16 @@
|
||||
|
||||
### Next Version
|
||||
* Partial support for timed metadata on Android MediaPlayer [#707](https://github.com/react-native-community/react-native-video/pull/707)
|
||||
* Update to ExoPlayer 2.8.2. Android SDK 26 now required [#1170](https://github.com/react-native-community/react-native-video/pull/1170)
|
||||
* Support video caching for iOS [#955](https://github.com/react-native-community/react-native-video/pull/955)
|
||||
* Video caching cleanups [#1172](https://github.com/react-native-community/react-native-video/pull/1172)
|
||||
* Add ipod-library support [#926](https://github.com/react-native-community/react-native-video/pull/926/files)
|
||||
* Fix crash on ExoPlayer when there are no audio tracks [#1233](https://github.com/react-native-community/react-native-video/pull/1233)
|
||||
* Reduce package size [#1231](https://github.com/react-native-community/react-native-video/pull/1231)
|
||||
* Remove unnecessary import in TextTrackType [#1229](https://github.com/react-native-community/react-native-video/pull/1229)
|
||||
* Prevent flash between poster and video [#1167](https://github.com/react-native-community/react-native-video/pull/1167)
|
||||
* Support react-native-dom [#1253](https://github.com/react-native-community/react-native-video/pull/1253)
|
||||
* Update to ExoPlayer 2.8.2. Android SDK 26 now required [#1170](https://github.com/react-native-community/react-native-video/pull/1170)
|
||||
* Update to ExoPlayer 2.8.4 [#1266](https://github.com/react-native-community/react-native-video/pull/1266)
|
||||
|
||||
### Version 3.2.0
|
||||
* Basic fullscreen support for Android MediaPlayer [#1138](https://github.com/react-native-community/react-native-video/pull/1138)
|
||||
|
87
README.md
87
README.md
@ -192,6 +192,31 @@ using System.Collections.Generic;
|
||||
```
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>DOM</summary>
|
||||
|
||||
Make the following additions to the given files manually:
|
||||
|
||||
**dom/bootstrap.js**
|
||||
|
||||
Import RCTVideoManager and add it to the list of nativeModules:
|
||||
|
||||
```javascript
|
||||
import { RNDomInstance } from "react-native-dom";
|
||||
import { name as appName } from "../app.json";
|
||||
import RCTVideoManager from 'react-native-video/dom/RCTVideoManager'; // Add this
|
||||
|
||||
// Path to RN Bundle Entrypoint ================================================
|
||||
const rnBundlePath = "./entry.bundle?platform=dom&dev=true";
|
||||
|
||||
// React Native DOM Runtime Options =============================================
|
||||
const ReactNativeDomOptions = {
|
||||
enableHotReload: false,
|
||||
nativeModules: [RCTVideoManager] // Add this
|
||||
};
|
||||
```
|
||||
</details>
|
||||
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
@ -208,7 +233,6 @@ import Video from 'react-native-video';
|
||||
this.player = ref
|
||||
}} // Store reference
|
||||
onBuffer={this.onBuffer} // Callback when remote video is buffering
|
||||
onEnd={this.onEnd} // Callback when playback finishes
|
||||
onError={this.videoError} // Callback when video cannot be loaded
|
||||
style={styles.backgroundVideo} />
|
||||
|
||||
@ -228,8 +252,10 @@ var styles = StyleSheet.create({
|
||||
* [allowsExternalPlayback](#allowsexternalplayback)
|
||||
* [audioOnly](#audioonly)
|
||||
* [bufferConfig](#bufferconfig)
|
||||
* [fullscreen (deprecated)](#fullscreen)
|
||||
* [controls](#controls)
|
||||
* [fullscreen](#fullscreen)
|
||||
* [fullscreenOptions](#fullscreenOptions)
|
||||
* [headers](#headers)
|
||||
* [ignoreSilentSwitch](#ignoresilentswitch)
|
||||
* [muted](#muted)
|
||||
* [paused](#paused)
|
||||
@ -251,6 +277,8 @@ var styles = StyleSheet.create({
|
||||
|
||||
### Event props
|
||||
* [onAudioBecomingNoisy](#onaudiobecomingnoisy)
|
||||
* [onEnd](#onend)
|
||||
* [onExternalPlaybackChange](#onexternalplaybackchange)
|
||||
* [onFullscreenPlayerWillPresent](#onfullscreenplayerwillpresent)
|
||||
* [onFullscreenPlayerDidPresent](#onfullscreenplayerdidpresent)
|
||||
* [onFullscreenPlayerWillDismiss](#onfullscreenplayerwilldismiss)
|
||||
@ -307,14 +335,21 @@ bufferConfig={{
|
||||
|
||||
Platforms: Android ExoPlayer
|
||||
|
||||
#### fullscreen (deprecated)
|
||||
#### controls
|
||||
Determines whether to show player controls.
|
||||
* ** false (default)** - Don't show player controls
|
||||
* **true** - Show player controls
|
||||
|
||||
Note on iOS, controls are always shown when in fullscreen mode.
|
||||
|
||||
Platforms: DOM, iOS
|
||||
|
||||
#### fullscreen
|
||||
Controls whether the player enters fullscreen on play. Use fullscreenOptions for extended behaviour.
|
||||
|
||||
Platforms: iOS
|
||||
|
||||
#### fullscreenOptions
|
||||
|
||||
Controls behaviour of the player entering fullscreen, such as forcing landscape playback on portrait devices
|
||||
|
||||
Property | Type | Description
|
||||
@ -334,6 +369,21 @@ fullscreenOptions={{
|
||||
|
||||
Platforms: iOS
|
||||
|
||||
#### headers
|
||||
Pass headers to the HTTP client. Can be used for authorization.
|
||||
|
||||
To enable this on iOS, you will need to manually edit RCTVideo.m and uncomment the header code in the playerItemForSource function. This is because the code used a private API and may cause your app to be rejected by the App Store. Use at your own risk.
|
||||
|
||||
Example:
|
||||
```
|
||||
headers = {{
|
||||
Authorization: 'bearer some-token-value',
|
||||
'X-Custom-Header': 'some value'
|
||||
}}
|
||||
```
|
||||
|
||||
Platforms: Android ExoPlayer
|
||||
|
||||
#### ignoreSilentSwitch
|
||||
Controls the iOS silent switch behavior
|
||||
* **"inherit" (default)** - Use the default AVPlayer behavior
|
||||
@ -615,6 +665,31 @@ Payload: none
|
||||
|
||||
Platforms: Android ExoPlayer, iOS
|
||||
|
||||
#### onEnd
|
||||
Callback function that is called when the player reaches the end of the media.
|
||||
|
||||
Payload: none
|
||||
|
||||
Platforms: all
|
||||
|
||||
#### onExternalPlaybackChange
|
||||
Callback function that is called when external playback mode for current playing video has changed. Mostly useful when connecting/disconnecting to Apple TV – it's called on connection/disconnection.
|
||||
|
||||
Payload:
|
||||
|
||||
Property | Type | Description
|
||||
--- | --- | ---
|
||||
isExternalPlaybackActive | boolean | Boolean indicating whether external playback mode is active
|
||||
|
||||
Example:
|
||||
```
|
||||
{
|
||||
isExternalPlaybackActive: true
|
||||
}
|
||||
```
|
||||
|
||||
Platforms: iOS
|
||||
|
||||
#### onFullscreenPlayerWillPresent
|
||||
Callback function that is called when the player is about to enter fullscreen mode.
|
||||
|
||||
@ -726,6 +801,8 @@ Example:
|
||||
}
|
||||
```
|
||||
|
||||
Platforms: all
|
||||
|
||||
#### onTimedMetadata
|
||||
Callback function that is called when timed metadata becomes available
|
||||
|
||||
@ -771,7 +848,7 @@ this.player.dismissFullscreenPlayer();
|
||||
|
||||
Platforms: Android ExoPlayer, Android MediaPlayer, iOS
|
||||
|
||||
#### FullscreenPlayer
|
||||
#### presentFullscreenPlayer
|
||||
`presentFullscreenPlayer()`
|
||||
|
||||
Put the player in fullscreen mode.
|
||||
|
@ -1,5 +1,3 @@
|
||||
import keyMirror from 'keymirror';
|
||||
|
||||
export default {
|
||||
SRT: 'application/x-subrip',
|
||||
TTML: 'application/ttml+xml',
|
||||
|
49
Video.js
49
Video.js
@ -172,6 +172,12 @@ export default class Video extends Component {
|
||||
this.props.onPlaybackRateChange(event.nativeEvent);
|
||||
}
|
||||
};
|
||||
|
||||
_onExternalPlaybackChange = (event) => {
|
||||
if (this.props.onExternalPlaybackChange) {
|
||||
this.props.onExternalPlaybackChange(event.nativeEvent);
|
||||
}
|
||||
}
|
||||
|
||||
_onAudioBecomingNoisy = () => {
|
||||
if (this.props.onAudioBecomingNoisy) {
|
||||
@ -236,6 +242,7 @@ export default class Video extends Component {
|
||||
onVideoBuffer: this._onBuffer,
|
||||
onTimedMetadata: this._onTimedMetadata,
|
||||
onVideoAudioBecomingNoisy: this._onAudioBecomingNoisy,
|
||||
onVideoExternalPlaybackChange: this._onExternalPlaybackChange,
|
||||
onVideoFullscreenPlayerWillPresent: this._onFullscreenPlayerWillPresent,
|
||||
onVideoFullscreenPlayerDidPresent: this._onFullscreenPlayerDidPresent,
|
||||
onVideoFullscreenPlayerWillDismiss: this._onFullscreenPlayerWillDismiss,
|
||||
@ -248,35 +255,21 @@ export default class Video extends Component {
|
||||
onAudioBecomingNoisy: this._onAudioBecomingNoisy,
|
||||
});
|
||||
|
||||
if (this.props.poster && this.state.showPoster) {
|
||||
const posterStyle = {
|
||||
position: 'absolute',
|
||||
left: 0,
|
||||
top: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
resizeMode: this.props.posterResizeMode || 'contain'
|
||||
};
|
||||
|
||||
return (
|
||||
<View style={nativeProps.style}>
|
||||
<RCTVideo
|
||||
ref={this._assignRoot}
|
||||
{...nativeProps}
|
||||
/>
|
||||
<Image
|
||||
style={posterStyle}
|
||||
source={{uri: this.props.poster}}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
const posterStyle = {
|
||||
...StyleSheet.absoluteFillObject,
|
||||
resizeMode: this.props.posterResizeMode || 'contain',
|
||||
};
|
||||
|
||||
return (
|
||||
<RCTVideo
|
||||
ref={this._assignRoot}
|
||||
{...nativeProps}
|
||||
/>
|
||||
<React.Fragment>
|
||||
<RCTVideo ref={this._assignRoot} {...nativeProps} />
|
||||
{this.props.poster &&
|
||||
this.state.showPoster && (
|
||||
<View style={nativeProps.style}>
|
||||
<Image style={posterStyle} source={{ uri: this.props.poster }} />
|
||||
</View>
|
||||
)}
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -303,6 +296,7 @@ Video.propTypes = {
|
||||
onVideoEnd: PropTypes.func,
|
||||
onTimedMetadata: PropTypes.func,
|
||||
onVideoAudioBecomingNoisy: PropTypes.func,
|
||||
onVideoExternalPlaybackChange: PropTypes.func,
|
||||
onVideoFullscreenPlayerWillPresent: PropTypes.func,
|
||||
onVideoFullscreenPlayerDidPresent: PropTypes.func,
|
||||
onVideoFullscreenPlayerWillDismiss: PropTypes.func,
|
||||
@ -384,6 +378,7 @@ Video.propTypes = {
|
||||
onPlaybackRateChange: PropTypes.func,
|
||||
onAudioFocusChanged: PropTypes.func,
|
||||
onAudioBecomingNoisy: PropTypes.func,
|
||||
onExternalPlaybackChange: PropTypes.func,
|
||||
|
||||
/* Required by react-native */
|
||||
scaleX: PropTypes.number,
|
||||
|
@ -19,7 +19,7 @@ android {
|
||||
dependencies {
|
||||
//noinspection GradleDynamicVersion
|
||||
provided "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
|
||||
compile('com.google.android.exoplayer:exoplayer:2.8.2') {
|
||||
compile('com.google.android.exoplayer:exoplayer:2.8.4') {
|
||||
exclude group: 'com.android.support'
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ dependencies {
|
||||
compile "com.android.support:support-compat:${safeExtGet('supportLibVersion', '+')}"
|
||||
compile "com.android.support:support-media-compat:${safeExtGet('supportLibVersion', '+')}"
|
||||
|
||||
compile('com.google.android.exoplayer:extension-okhttp:2.8.2') {
|
||||
compile('com.google.android.exoplayer:extension-okhttp:2.8.4') {
|
||||
exclude group: 'com.squareup.okhttp3', module: 'okhttp'
|
||||
}
|
||||
compile 'com.squareup.okhttp3:okhttp:3.11.0'
|
||||
|
@ -830,6 +830,10 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
}
|
||||
|
||||
private int getTrackIndexForDefaultLocale(TrackGroupArray groups) {
|
||||
if (groups.length == 0) { // Avoid a crash if we try to select a non-existant group
|
||||
return C.INDEX_UNSET;
|
||||
}
|
||||
|
||||
int trackIndex = 0; // default if no match
|
||||
String locale2 = Locale.getDefault().getLanguage(); // 2 letter code
|
||||
String locale3 = Locale.getDefault().getISO3Language(); // 3 letter code
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.brentvatne.react;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.graphics.Matrix;
|
||||
|
9
dom/LICENSE.md
Normal file
9
dom/LICENSE.md
Normal file
@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Vincent Riemer
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
248
dom/RCTVideo.js
Normal file
248
dom/RCTVideo.js
Normal file
@ -0,0 +1,248 @@
|
||||
// @flow
|
||||
|
||||
import { RCTEvent, RCTView, type RCTBridge } from "react-native-dom";
|
||||
|
||||
import resizeModes from "./resizeModes";
|
||||
import type { VideoSource } from "./types";
|
||||
import RCTVideoEvent from "./RCTVideoEvent";
|
||||
|
||||
class RCTVideo extends RCTView {
|
||||
playPromise: Promise<void> = Promise.resolve();
|
||||
progressTimer: number;
|
||||
videoElement: HTMLVideoElement;
|
||||
|
||||
onEnd: boolean = false;
|
||||
onLoad: boolean = false;
|
||||
onLoadStart: boolean = false;
|
||||
onProgress: boolean = false;
|
||||
|
||||
_paused: boolean = false;
|
||||
_progressUpdateInterval: number = 250.0;
|
||||
_savedVolume: number = 1.0;
|
||||
|
||||
constructor(bridge: RCTBridge) {
|
||||
super(bridge);
|
||||
|
||||
this.eventDispatcher = bridge.getModuleByName("EventDispatcher");
|
||||
|
||||
this.onEnd = this.onEnd.bind(this);
|
||||
this.onLoad = this.onLoad.bind(this);
|
||||
this.onLoadStart = this.onLoadStart.bind(this);
|
||||
this.onPlay = this.onPlay.bind(this);
|
||||
this.onProgress = this.onProgress.bind(this);
|
||||
|
||||
this.videoElement = this.initializeVideoElement();
|
||||
this.videoElement.addEventListener("ended", this.onEnd);
|
||||
this.videoElement.addEventListener("loadeddata", this.onLoad);
|
||||
this.videoElement.addEventListener("loadstart", this.onLoadStart);
|
||||
this.videoElement.addEventListener("pause", this.onPause);
|
||||
this.videoElement.addEventListener("play", this.onPlay);
|
||||
|
||||
this.muted = false;
|
||||
this.rate = 1.0;
|
||||
this.volume = 1.0;
|
||||
this.videoElement.autoplay = true;
|
||||
this.childContainer.appendChild(this.videoElement);
|
||||
}
|
||||
|
||||
detachFromView(view: UIView) {
|
||||
this.videoElement.removeEventListener("ended", this.onEnd);
|
||||
this.videoElement.removeEventListener("loadeddata", this.onLoad);
|
||||
this.videoElement.removeEventListener("loadstart", this.onLoadStart);
|
||||
this.videoElement.removeEventListener("pause", this.onPause);
|
||||
this.videoElement.removeEventListener("play", this.onPlay);
|
||||
|
||||
this.stopProgressTimer();
|
||||
}
|
||||
|
||||
initializeVideoElement() {
|
||||
const elem = document.createElement("video");
|
||||
|
||||
Object.assign(elem.style, {
|
||||
display: "block",
|
||||
position: "absolute",
|
||||
top: "0",
|
||||
left: "0",
|
||||
width: "100%",
|
||||
height: "100%"
|
||||
});
|
||||
|
||||
return elem;
|
||||
}
|
||||
|
||||
presentFullscreenPlayer() {
|
||||
console.log("V PF");
|
||||
this.videoElement.webkitRequestFullScreen();
|
||||
}
|
||||
|
||||
set controls(value: boolean) {
|
||||
if (value) {
|
||||
this.videoElement.controls = true;
|
||||
this.videoElement.style.pointerEvents = "auto";
|
||||
} else {
|
||||
this.videoElement.controls = false;
|
||||
this.videoElement.style.pointerEvents = "";
|
||||
}
|
||||
}
|
||||
|
||||
set muted(value: boolean) {
|
||||
if (value) {
|
||||
this.videoElement.muted = true;
|
||||
} else {
|
||||
this.videoElement.muted = false;
|
||||
}
|
||||
}
|
||||
|
||||
set paused(value: boolean) {
|
||||
this.playPromise.then(() => {
|
||||
if (value) {
|
||||
this.videoElement.pause();
|
||||
} else {
|
||||
this.playPromise = this.videoElement.play();
|
||||
}
|
||||
});
|
||||
this._paused = value;
|
||||
}
|
||||
|
||||
set progressUpdateInterval(value: number) {
|
||||
this._progressUpdateInterval = value;
|
||||
this.stopProgressTimer();
|
||||
if (!this._paused) {
|
||||
this.startProgressTimer();
|
||||
}
|
||||
}
|
||||
|
||||
set rate(value: number) {
|
||||
this.videoElement.defaultPlaybackRate = value; // playbackRate doesn't work on Chrome
|
||||
this.videoElement.playbackRate = value;
|
||||
}
|
||||
|
||||
set repeat(value: boolean) {
|
||||
if (value) {
|
||||
this.videoElement.setAttribute("loop", "true");
|
||||
} else {
|
||||
this.videoElement.removeAttribute("loop");
|
||||
}
|
||||
}
|
||||
|
||||
set resizeMode(value: number) {
|
||||
switch (value) {
|
||||
case resizeModes.ScaleNone: {
|
||||
this.videoElement.style.objectFit = "none";
|
||||
break;
|
||||
}
|
||||
case resizeModes.ScaleToFill: {
|
||||
this.videoElement.style.objectFit = "fill";
|
||||
break;
|
||||
}
|
||||
case resizeModes.ScaleAspectFit: {
|
||||
this.videoElement.style.objectFit = "contain";
|
||||
break;
|
||||
}
|
||||
case resizeModes.ScaleAspectFill: {
|
||||
this.videoElement.style.objectFit = "cover";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
set seek(value: number) {
|
||||
this.videoElement.currentTime = value;
|
||||
}
|
||||
|
||||
set source(value: VideoSource) {
|
||||
let uri = value.uri;
|
||||
|
||||
if (uri.startsWith("blob:")) {
|
||||
let blob = this.bridge.blobManager.resolveURL(uri);
|
||||
if (blob.type === "text/xml") {
|
||||
blob = new Blob([blob], { type: "video/mp4" });
|
||||
}
|
||||
uri = URL.createObjectURL(blob);
|
||||
}
|
||||
|
||||
this.videoElement.setAttribute("src", uri);
|
||||
if (!this._paused) {
|
||||
this.playPromise = this.videoElement.play();
|
||||
}
|
||||
}
|
||||
|
||||
set volume(value: number) {
|
||||
if (value === 0) {
|
||||
this.muted = true;
|
||||
} else {
|
||||
this.videoElement.volume = value;
|
||||
this.muted = false;
|
||||
}
|
||||
}
|
||||
|
||||
onEnd = () => {
|
||||
this.onProgress();
|
||||
this.sendEvent("topVideoEnd", null);
|
||||
this.stopProgressTimer();
|
||||
}
|
||||
|
||||
onLoad = () => {
|
||||
// height & width are safe with audio, will be 0
|
||||
const height = this.videoElement.videoHeight;
|
||||
const width = this.videoElement.videoWidth;
|
||||
const payload = {
|
||||
currentPosition: this.videoElement.currentTime,
|
||||
duration: this.videoElement.duration,
|
||||
naturalSize: {
|
||||
width,
|
||||
height,
|
||||
orientation: width >= height ? "landscape" : "portrait"
|
||||
}
|
||||
};
|
||||
this.sendEvent("topVideoLoad", payload);
|
||||
}
|
||||
|
||||
onLoadStart = () => {
|
||||
const src = this.videoElement.currentSrc;
|
||||
const payload = {
|
||||
isNetwork: !src.match(/^https?:\/\/localhost/), // require is served from localhost
|
||||
uri: this.videoElement.currentSrc
|
||||
};
|
||||
this.sendEvent("topVideoLoadStart", payload);
|
||||
}
|
||||
|
||||
onPause = () => {
|
||||
this.stopProgressTimer();
|
||||
}
|
||||
|
||||
onPlay = () => {
|
||||
this.startProgressTimer();
|
||||
}
|
||||
|
||||
onProgress = () => {
|
||||
const payload = {
|
||||
currentTime: this.videoElement.currentTime,
|
||||
seekableDuration: this.videoElement.duration
|
||||
};
|
||||
this.sendEvent("topVideoProgress", payload);
|
||||
}
|
||||
|
||||
sendEvent(eventName, payload) {
|
||||
const event = new RCTVideoEvent(eventName, this.reactTag, 0, payload);
|
||||
this.eventDispatcher.sendEvent(event);
|
||||
}
|
||||
|
||||
startProgressTimer() {
|
||||
if (!this.progressTimer && this._progressUpdateInterval) {
|
||||
this.onProgress();
|
||||
this.progressTimer = setInterval(this.onProgress, this._progressUpdateInterval);
|
||||
}
|
||||
}
|
||||
|
||||
stopProgressTimer() {
|
||||
if (this.progressTimer) {
|
||||
clearInterval(this.progressTimer);
|
||||
this.progressTimer = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define("rct-video", RCTVideo);
|
||||
|
||||
export default RCTVideo;
|
56
dom/RCTVideoEvent.js
Normal file
56
dom/RCTVideoEvent.js
Normal file
@ -0,0 +1,56 @@
|
||||
// import { RCTEvent } from "react-native-dom";
|
||||
|
||||
interface RCTEvent {
|
||||
viewTag: number;
|
||||
eventName: string;
|
||||
coalescingKey: number;
|
||||
|
||||
canCoalesce(): boolean;
|
||||
coalesceWithEvent(event: RCTEvent): RCTEvent;
|
||||
|
||||
moduleDotMethod(): string;
|
||||
arguments(): Array<any>;
|
||||
}
|
||||
|
||||
export default class RCTVideoEvent implements RCTEvent {
|
||||
viewTag: number;
|
||||
eventName: string;
|
||||
coalescingKey: number;
|
||||
|
||||
constructor(
|
||||
eventName: string,
|
||||
reactTag: number,
|
||||
coalescingKey: number,
|
||||
data: ?Object
|
||||
) {
|
||||
this.viewTag = reactTag;
|
||||
this.eventName = eventName;
|
||||
this.coalescingKey = coalescingKey;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
canCoalesce(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
coalesceWithEvent(event: RCTEvent): RCTEvent {
|
||||
return;
|
||||
}
|
||||
|
||||
moduleDotMethod(): string {
|
||||
return "RCTEventEmitter.receiveEvent";
|
||||
}
|
||||
|
||||
arguments(): Array<any> {
|
||||
const args = [
|
||||
this.viewTag,
|
||||
this.eventName,
|
||||
this.data
|
||||
];
|
||||
return args;
|
||||
}
|
||||
|
||||
coalescingKey(): number {
|
||||
return this.coalescingKey;
|
||||
}
|
||||
}
|
77
dom/RCTVideoManager.js
Normal file
77
dom/RCTVideoManager.js
Normal file
@ -0,0 +1,77 @@
|
||||
// @flow
|
||||
|
||||
import { RCTViewManager } from "react-native-dom";
|
||||
|
||||
import RCTVideo from "./RCTVideo";
|
||||
import resizeModes from "./resizeModes";
|
||||
|
||||
import type { VideoSource } from "./types";
|
||||
|
||||
class RCTVideoManager extends RCTViewManager {
|
||||
static moduleName = "RCTVideoManager";
|
||||
|
||||
view() {
|
||||
return new RCTVideo(this.bridge);
|
||||
}
|
||||
|
||||
describeProps() {
|
||||
return super
|
||||
.describeProps()
|
||||
.addBooleanProp("controls", this.setControls)
|
||||
.addBooleanProp("muted", this.setMuted)
|
||||
.addBooleanProp("paused", this.setPaused)
|
||||
.addNumberProp("progressUpdateInterval", this.setProgressUpdateInterval)
|
||||
.addBooleanProp("rate", this.setRate)
|
||||
.addBooleanProp("repeat", this.setRepeat)
|
||||
.addNumberProp("resizeMode", this.setResizeMode)
|
||||
.addNumberProp("seek", this.setSeek)
|
||||
.addObjectProp("src", this.setSource)
|
||||
.addNumberProp("volume", this.setVolume)
|
||||
.addDirectEvent("onVideoEnd")
|
||||
.addDirectEvent("onVideoLoad")
|
||||
.addDirectEvent("onVideoLoadStart")
|
||||
.addDirectEvent("onVideoProgress");
|
||||
}
|
||||
|
||||
presentFullscreenPlayer() {
|
||||
// not currently working
|
||||
}
|
||||
|
||||
setControls(view: RCTVideo, value: boolean) {
|
||||
view.controls = value;
|
||||
}
|
||||
|
||||
setMuted(view: RCTVideo, value: boolean) {
|
||||
view.muted = value;
|
||||
}
|
||||
|
||||
setPaused(view: RCTVideo, value: boolean) {
|
||||
view.paused = value;
|
||||
}
|
||||
|
||||
setRate(view: RCTVideo, value: number) {
|
||||
view.rate = value;
|
||||
}
|
||||
|
||||
setRepeat(view: RCTVideo, value: boolean) {
|
||||
view.repeat = value;
|
||||
}
|
||||
|
||||
setResizeMode(view: RCTVideo, value: number) {
|
||||
view.resizeMode = value;
|
||||
}
|
||||
|
||||
setSeek(view: RCTVideo, value: number) {
|
||||
view.seek = value;
|
||||
}
|
||||
|
||||
setSource(view: RCTVideo, value: VideoSource) {
|
||||
view.source = value;
|
||||
}
|
||||
|
||||
constantsToExport() {
|
||||
return { ...resizeModes };
|
||||
}
|
||||
}
|
||||
|
||||
export default RCTVideoManager;
|
3
dom/index.js
Normal file
3
dom/index.js
Normal file
@ -0,0 +1,3 @@
|
||||
// @flow
|
||||
|
||||
module.exports = require("./RCTVideoManager");
|
8
dom/resizeModes.js
Normal file
8
dom/resizeModes.js
Normal file
@ -0,0 +1,8 @@
|
||||
// @flow
|
||||
|
||||
export default {
|
||||
ScaleNone: 0,
|
||||
ScaleToFill: 1,
|
||||
ScaleAspectFit: 2,
|
||||
ScaleAspectFill: 3,
|
||||
};
|
10
dom/types.js
Normal file
10
dom/types.js
Normal file
@ -0,0 +1,10 @@
|
||||
// @flow
|
||||
|
||||
export type VideoSource = {
|
||||
uri: string,
|
||||
type: string,
|
||||
mainVer: number,
|
||||
patchVer: number,
|
||||
isNetwork: boolean,
|
||||
isAsset: boolean,
|
||||
};
|
@ -35,6 +35,7 @@
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onPlaybackStalled;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onPlaybackResume;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onPlaybackRateChange;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onVideoExternalPlaybackChange;
|
||||
|
||||
- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
|
@ -12,6 +12,7 @@ static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty";
|
||||
static NSString *const readyForDisplayKeyPath = @"readyForDisplay";
|
||||
static NSString *const playbackRate = @"rate";
|
||||
static NSString *const timedMetadata = @"timedMetadata";
|
||||
static NSString *const externalPlaybackActive = @"externalPlaybackActive";
|
||||
|
||||
static int const RCTVideoUnset = -1;
|
||||
|
||||
@ -35,6 +36,7 @@ static int const RCTVideoUnset = -1;
|
||||
/* Required to publish events */
|
||||
RCTEventDispatcher *_eventDispatcher;
|
||||
BOOL _playbackRateObserverRegistered;
|
||||
BOOL _isExternalPlaybackActiveObserverRegistered;
|
||||
BOOL _videoLoadStarted;
|
||||
|
||||
bool _pendingSeek;
|
||||
@ -76,6 +78,7 @@ static int const RCTVideoUnset = -1;
|
||||
_eventDispatcher = eventDispatcher;
|
||||
|
||||
_playbackRateObserverRegistered = NO;
|
||||
_isExternalPlaybackActiveObserverRegistered = NO;
|
||||
_playbackStalled = NO;
|
||||
_rate = 1.0;
|
||||
_volume = 1.0;
|
||||
@ -342,12 +345,19 @@ static int const RCTVideoUnset = -1;
|
||||
[_player removeObserver:self forKeyPath:playbackRate context:nil];
|
||||
_playbackRateObserverRegistered = NO;
|
||||
}
|
||||
if (_isExternalPlaybackActiveObserverRegistered) {
|
||||
[_player removeObserver:self forKeyPath:externalPlaybackActive context:nil];
|
||||
_isExternalPlaybackActiveObserverRegistered = NO;
|
||||
}
|
||||
|
||||
_player = [AVPlayer playerWithPlayerItem:_playerItem];
|
||||
_player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
|
||||
|
||||
[_player addObserver:self forKeyPath:playbackRate options:0 context:nil];
|
||||
_playbackRateObserverRegistered = YES;
|
||||
|
||||
[_player addObserver:self forKeyPath:externalPlaybackActive options:0 context:nil];
|
||||
_isExternalPlaybackActiveObserverRegistered = YES;
|
||||
|
||||
[self addPlayerTimeObserver];
|
||||
|
||||
@ -659,6 +669,12 @@ static int const RCTVideoUnset = -1;
|
||||
_playbackStalled = NO;
|
||||
}
|
||||
}
|
||||
else if([keyPath isEqualToString:externalPlaybackActive]) {
|
||||
if(self.onVideoExternalPlaybackChange) {
|
||||
self.onVideoExternalPlaybackChange(@{@"isExternalPlaybackActive": [NSNumber numberWithBool:_player.isExternalPlaybackActive],
|
||||
@"target": self.reactTag});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
||||
}
|
||||
@ -1328,6 +1344,10 @@ static int const RCTVideoUnset = -1;
|
||||
[_player removeObserver:self forKeyPath:playbackRate context:nil];
|
||||
_playbackRateObserverRegistered = NO;
|
||||
}
|
||||
if (_isExternalPlaybackActiveObserverRegistered) {
|
||||
[_player removeObserver:self forKeyPath:externalPlaybackActive context:nil];
|
||||
_isExternalPlaybackActiveObserverRegistered = NO;
|
||||
}
|
||||
_player = nil;
|
||||
|
||||
[self removePlayerLayer];
|
||||
|
@ -57,6 +57,7 @@ RCT_EXPORT_VIEW_PROPERTY(onReadyForDisplay, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onPlaybackStalled, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onPlaybackResume, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onPlaybackRateChange, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoExternalPlaybackChange, RCTBubblingEventBlock);
|
||||
|
||||
- (NSDictionary *)constantsToExport
|
||||
{
|
||||
|
13
package.json
13
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-video",
|
||||
"version": "3.2.0",
|
||||
"version": "3.2.1",
|
||||
"description": "A <Video /> element for react-native",
|
||||
"main": "Video.js",
|
||||
"license": "MIT",
|
||||
@ -44,5 +44,14 @@
|
||||
"android": {
|
||||
"sourceDir": "./android-exoplayer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"files":[
|
||||
"android-exoplayer",
|
||||
"android",
|
||||
"ios",
|
||||
"windows",
|
||||
"TextTrackType.js",
|
||||
"react-native-video.podspec",
|
||||
"VideoResizeMode.js"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user