diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..5ee6f693 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,20 @@ +Thanks for opening a PR! +Since this is a volunteer project and is very active, anything you can do to reduce the amount of time needed to review and merge your PR is appreciated. +The following steps will help get your PR merged quickly: + +#### Update the documentation +If you've added new functionality, update the README.md with an entry for your prop or event. +The entry should be inserted in alphabetical order. + +#### Update the changelog +After you open the PR, update the CHANGELOG.md file with an entry pointing to your PR. + +#### Provide an example of how to test the change +If the PR requires special testing setup provide all the relevant instructions and files. This may include a sample video file or URL, configuration, or setup steps. + +#### Focus the PR on only one area +Testing multiple features takes longer than isolated changes and if there is a bug in one feature, prevents the other parts of your PR from getting merged until it gets fixed. +If you're touching multiple different areas that aren't related, break the changes up into multiple PRs. + +#### Describe the changes +Add a note describing what your PR does. If there is a change to the behavior of the code, explain why it needs to be updated. diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 46b411bf..00000000 --- a/.npmignore +++ /dev/null @@ -1 +0,0 @@ -/examples diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ac26914..ad2684f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,17 @@ ### 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) +* Add fullscreenOrientation option for iOS [#1215](https://github.com/react-native-community/react-native-video/pull/1215) ### Version 3.2.0 * Basic fullscreen support for Android MediaPlayer [#1138](https://github.com/react-native-community/react-native-video/pull/1138) diff --git a/README.md b/README.md index c1dd0f0f..27c25742 100644 --- a/README.md +++ b/README.md @@ -192,6 +192,31 @@ using System.Collections.Generic; ``` +
+ DOM + +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 +}; +``` +
+ ## 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,6 +252,11 @@ var styles = StyleSheet.create({ * [allowsExternalPlayback](#allowsexternalplayback) * [audioOnly](#audioonly) * [bufferConfig](#bufferconfig) +* [controls](#controls) +* [fullscreen](#fullscreen) +* [fullscreenOrientation](#fullscreenorientation) +* [headers](#headers) +* [id](#id) * [ignoreSilentSwitch](#ignoresilentswitch) * [muted](#muted) * [paused](#paused) @@ -249,6 +278,8 @@ var styles = StyleSheet.create({ ### Event props * [onAudioBecomingNoisy](#onaudiobecomingnoisy) +* [onEnd](#onend) +* [onExternalPlaybackChange](#onexternalplaybackchange) * [onFullscreenPlayerWillPresent](#onfullscreenplayerwillpresent) * [onFullscreenPlayerDidPresent](#onfullscreenplayerdidpresent) * [onFullscreenPlayerWillDismiss](#onfullscreenplayerwilldismiss) @@ -305,6 +336,55 @@ bufferConfig={{ Platforms: Android ExoPlayer +#### 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. +* **false (default)** - Don't display the video in fullscreen +* **true** - Display the video in fullscreen + +Platforms: iOS + +#### fullscreenOrientation + +* **all (default)** - +* **landscape** +* **portrait** + +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 + +#### id +Set the DOM id element so you can use document.getElementById on web platforms. Accepts string values. + +Example: +``` +id="video" +``` + +Platforms: DOM + #### ignoreSilentSwitch Controls the iOS silent switch behavior * **"inherit" (default)** - Use the default AVPlayer behavior @@ -586,6 +666,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. @@ -680,7 +785,7 @@ Example: Platforms: all #### onProgress -Callback function that is called every progressInterval seconds with info about which position the media is currently playing. +Callback function that is called every progressUpdateInterval seconds with info about which position the media is currently playing. Property | Type | Description --- | --- | --- @@ -697,6 +802,8 @@ Example: } ``` +Platforms: all + #### onTimedMetadata Callback function that is called when timed metadata becomes available @@ -742,7 +849,7 @@ this.player.dismissFullscreenPlayer(); Platforms: Android ExoPlayer, Android MediaPlayer, iOS -#### FullscreenPlayer +#### presentFullscreenPlayer `presentFullscreenPlayer()` Put the player in fullscreen mode. diff --git a/TextTrackType.js b/TextTrackType.js index caff65a9..9dc14077 100644 --- a/TextTrackType.js +++ b/TextTrackType.js @@ -1,5 +1,3 @@ -import keyMirror from 'keymirror'; - export default { SRT: 'application/x-subrip', TTML: 'application/ttml+xml', diff --git a/Video.js b/Video.js index e8203b8b..e430e419 100644 --- a/Video.js +++ b/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 ( - - - - - ); - } + const posterStyle = { + ...StyleSheet.absoluteFillObject, + resizeMode: this.props.posterResizeMode || 'contain', + }; return ( - + + + {this.props.poster && + this.state.showPoster && ( + + + + )} + ); } } @@ -298,6 +291,7 @@ Video.propTypes = { onVideoEnd: PropTypes.func, onTimedMetadata: PropTypes.func, onVideoAudioBecomingNoisy: PropTypes.func, + onVideoExternalPlaybackChange: PropTypes.func, onVideoFullscreenPlayerWillPresent: PropTypes.func, onVideoFullscreenPlayerDidPresent: PropTypes.func, onVideoFullscreenPlayerWillDismiss: PropTypes.func, @@ -360,6 +354,7 @@ Video.propTypes = { controls: PropTypes.bool, audioOnly: PropTypes.bool, currentTime: PropTypes.number, + fullscreenOrientation: PropTypes.oneOf(['all','landscape','portrait']), progressUpdateInterval: PropTypes.number, useTextureView: PropTypes.bool, onLoadStart: PropTypes.func, @@ -379,6 +374,7 @@ Video.propTypes = { onPlaybackRateChange: PropTypes.func, onAudioFocusChanged: PropTypes.func, onAudioBecomingNoisy: PropTypes.func, + onExternalPlaybackChange: PropTypes.func, /* Required by react-native */ scaleX: PropTypes.number, diff --git a/android-exoplayer/build.gradle b/android-exoplayer/build.gradle index cc93e1f6..0e4804f9 100644 --- a/android-exoplayer/build.gradle +++ b/android-exoplayer/build.gradle @@ -19,7 +19,7 @@ android { dependencies { //noinspection GradleDynamicVersion compileOnly "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}" - implementation('com.google.android.exoplayer:exoplayer:2.8.2') { + implementation('com.google.android.exoplayer:exoplayer:2.8.4') { exclude group: 'com.android.support' } @@ -28,7 +28,7 @@ dependencies { implementation "com.android.support:support-compat:${safeExtGet('supportLibVersion', '+')}" implementation "com.android.support:support-media-compat:${safeExtGet('supportLibVersion', '+')}" - implementation('com.google.android.exoplayer:extension-okhttp:2.8.2') { + implementation('com.google.android.exoplayer:extension-okhttp:2.8.4') { exclude group: 'com.squareup.okhttp3', module: 'okhttp' } implementation 'com.squareup.okhttp3:okhttp:3.11.0' diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index e098c72a..0c1a178f 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -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 diff --git a/android/src/main/java/com/brentvatne/react/ReactVideoView.java b/android/src/main/java/com/brentvatne/react/ReactVideoView.java index b7c2eec5..3ff17a1f 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoView.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoView.java @@ -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; diff --git a/dom/LICENSE.md b/dom/LICENSE.md new file mode 100644 index 00000000..aa185c82 --- /dev/null +++ b/dom/LICENSE.md @@ -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. diff --git a/dom/RCTVideo.js b/dom/RCTVideo.js new file mode 100644 index 00000000..9831b61d --- /dev/null +++ b/dom/RCTVideo.js @@ -0,0 +1,272 @@ +// @flow + +import { RCTEvent, RCTView, type RCTBridge } from "react-native-dom"; +import shaka from "shaka-player"; + +import resizeModes from "./resizeModes"; +import type { VideoSource } from "./types"; +import RCTVideoEvent from "./RCTVideoEvent"; + +class RCTVideo extends RCTView { + playPromise: Promise = 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"); + + shaka.polyfill.installAll(); + + 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.player = new shaka.Player(this.videoElement); + + this.muted = false; + this.rate = 1.0; + this.volume = 1.0; + 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() { + this.videoElement.webkitRequestFullScreen(); + } + + set controls(value: boolean) { + this.videoElement.controls = value; + this.videoElement.style.pointerEvents = value ? "auto" : ""; + } + + set id(value: string) { + this.videoElement.id = value; + } + + set muted(value: boolean) { + this.videoElement.muted = true; + } + + set paused(value: boolean) { + if (value) { + this.videoElement.pause(); + } else { + this.requestPlay(); + } + 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) { + this.videoElement.loop = value; + } + + 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); + } + + if (!shaka.Player.isBrowserSupported()) { // primarily iOS WebKit + this.videoElement.setAttribute("src", uri); + if (!this._paused) { + this.requestPlay(); + } + } else { + this.player.load(uri) + .then(() => { + if (!this._paused) { + this.requestPlay(); + } + }) + .catch(this.onError); + } + } + + 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(); + } + + onError = error => { + console.warn("topVideoError", error); + } + + 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); + } + + onRejectedAutoplay = () => { + this.sendEvent("topVideoRejectedAutoplay", null); + } + + requestPlay() { + const playPromise = this.videoElement.play(); + if (playPromise) { + playPromise + .then(() => {}) + .catch(e => { + /* This is likely one of: + * name: NotAllowedError - autoplay is not supported + * name: NotSupportedError - format is not supported + */ + this.onError({ code: e.name, message: e.message }); + }); + } + } + + 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; diff --git a/dom/RCTVideoEvent.js b/dom/RCTVideoEvent.js new file mode 100644 index 00000000..699a88c4 --- /dev/null +++ b/dom/RCTVideoEvent.js @@ -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; + } + +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 { + const args = [ + this.viewTag, + this.eventName, + this.data + ]; + return args; + } + + coalescingKey(): number { + return this.coalescingKey; + } +} diff --git a/dom/RCTVideoManager.js b/dom/RCTVideoManager.js new file mode 100644 index 00000000..2eb5309b --- /dev/null +++ b/dom/RCTVideoManager.js @@ -0,0 +1,87 @@ +// @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) + .addStringProp("id", this.setId) + .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("onVideoError") + .addDirectEvent("onVideoLoad") + .addDirectEvent("onVideoLoadStart") + .addDirectEvent("onVideoProgress"); + } + + dismissFullscreenPlayer() { + // not currently working + } + + presentFullscreenPlayer() { + // not currently working + } + + setControls(view: RCTVideo, value: boolean) { + view.controls = value; + } + + setId(view: RCTVideo, value: string) { + view.id = 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; diff --git a/dom/index.js b/dom/index.js new file mode 100644 index 00000000..d68d5bba --- /dev/null +++ b/dom/index.js @@ -0,0 +1,3 @@ +// @flow + +module.exports = require("./RCTVideoManager"); diff --git a/dom/resizeModes.js b/dom/resizeModes.js new file mode 100644 index 00000000..5f569e0d --- /dev/null +++ b/dom/resizeModes.js @@ -0,0 +1,8 @@ +// @flow + +export default { + ScaleNone: 0, + ScaleToFill: 1, + ScaleAspectFit: 2, + ScaleAspectFill: 3, +}; diff --git a/dom/types.js b/dom/types.js new file mode 100644 index 00000000..fe1d1a15 --- /dev/null +++ b/dom/types.js @@ -0,0 +1,10 @@ +// @flow + +export type VideoSource = { + uri: string, + type: string, + mainVer: number, + patchVer: number, + isNetwork: boolean, + isAsset: boolean, +}; diff --git a/examples/basic/ios/VideoPlayer-tvOS.plist b/examples/basic/ios/VideoPlayer-tvOS.plist new file mode 100644 index 00000000..ecbd496b --- /dev/null +++ b/examples/basic/ios/VideoPlayer-tvOS.plist @@ -0,0 +1,53 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + NSAppTransportSecurity + + NSExceptionDomains + + localhost + + NSExceptionAllowsInsecureHTTPLoads + + + + + NSLocationWhenInUseUsageDescription + + UILaunchStoryboardName + LaunchScreen + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UIViewControllerBasedStatusBarAppearance + + + diff --git a/examples/basic/ios/VideoPlayer.xcodeproj/project.pbxproj b/examples/basic/ios/VideoPlayer.xcodeproj/project.pbxproj index 4c3fa6f2..db5f9a39 100644 --- a/examples/basic/ios/VideoPlayer.xcodeproj/project.pbxproj +++ b/examples/basic/ios/VideoPlayer.xcodeproj/project.pbxproj @@ -12,7 +12,6 @@ 00C302E81ABCBA2D00DB3ED1 /* libRCTImage.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302C01ABCB91800DB3ED1 /* libRCTImage.a */; }; 00C302E91ABCBA2D00DB3ED1 /* libRCTNetwork.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302DC1ABCB9D200DB3ED1 /* libRCTNetwork.a */; }; 00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302E41ABCB9EE00DB3ED1 /* libRCTVibration.a */; }; - 00E356F31AD99517003FC87E /* VideoPlayerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* VideoPlayerTests.m */; }; 133E29F31AD74F7200F7D852 /* libRCTLinking.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 78C398B91ACF4ADC00677621 /* libRCTLinking.a */; }; 139105C61AF99C1200B5F7CC /* libRCTSettings.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 139105C11AF99BAD00B5F7CC /* libRCTSettings.a */; }; 139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 139FDEF41B06529B00C62182 /* libRCTWebSocket.a */; }; @@ -20,11 +19,21 @@ 13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB11A68108700A75B9A /* LaunchScreen.xib */; }; 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; - 140ED2AC1D01E1AD002B40FF /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; }; 146834051AC3E58100842450 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; }; 5E9157361DD0AC6A00FF2AA8 /* libRCTAnimation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E9157331DD0AC6500FF2AA8 /* libRCTAnimation.a */; }; 832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; }; 8C2A0F841E2560A100E31596 /* libRCTVideo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8C2A0F791E25608300E31596 /* libRCTVideo.a */; }; + FA3566AB216D5D7000E01ABD /* libRCTImage-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DAD3E841DF850E9000B6D8A /* libRCTImage-tvOS.a */; }; + FA3566AC216D5D7000E01ABD /* libRCTLinking-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DAD3E881DF850E9000B6D8A /* libRCTLinking-tvOS.a */; }; + FA3566AD216D5D7000E01ABD /* libRCTNetwork-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DAD3E8C1DF850E9000B6D8A /* libRCTNetwork-tvOS.a */; }; + FA3566AE216D5D7000E01ABD /* libRCTSettings-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DAD3E901DF850E9000B6D8A /* libRCTSettings-tvOS.a */; }; + FA3566AF216D5D7000E01ABD /* libRCTText-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DAD3E941DF850E9000B6D8A /* libRCTText-tvOS.a */; }; + FA3566B0216D5D7000E01ABD /* libRCTWebSocket-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DAD3E991DF850E9000B6D8A /* libRCTWebSocket-tvOS.a */; }; + FA3566C8216D5DA900E01ABD /* libRCTVideo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D1107C542111145500073188 /* libRCTVideo.a */; }; + FA8681B8216D5C6D0010C92A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; }; + FA8681B9216D5C6D0010C92A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; + FA8681C8216D5C6D0010C92A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; + FA8B47A5216D777200AB07CF /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DAD3EA31DF850E9000B6D8A /* libReact.a */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -63,13 +72,6 @@ remoteGlobalIDString = 832C81801AAF6DEF007FA2F7; remoteInfo = RCTVibration; }; - 00E356F41AD99517003FC87E /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 83CBB9F71A601CBA00E9B192 /* Project object */; - proxyType = 1; - remoteGlobalIDString = 13B07F861A680F5B00A75B9A; - remoteInfo = VideoPlayer; - }; 139105C01AF99BAD00B5F7CC /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 139105B61AF99BAD00B5F7CC /* RCTSettings.xcodeproj */; @@ -303,9 +305,6 @@ 00C302BB1ABCB91800DB3ED1 /* RCTImage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTImage.xcodeproj; path = "../node_modules/react-native/Libraries/Image/RCTImage.xcodeproj"; sourceTree = ""; }; 00C302D31ABCB9D200DB3ED1 /* RCTNetwork.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTNetwork.xcodeproj; path = "../node_modules/react-native/Libraries/Network/RCTNetwork.xcodeproj"; sourceTree = ""; }; 00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTVibration.xcodeproj; path = "../node_modules/react-native/Libraries/Vibration/RCTVibration.xcodeproj"; sourceTree = ""; }; - 00E356EE1AD99517003FC87E /* VideoPlayerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = VideoPlayerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 00E356F11AD99517003FC87E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 00E356F21AD99517003FC87E /* VideoPlayerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VideoPlayerTests.m; sourceTree = ""; }; 139105B61AF99BAD00B5F7CC /* RCTSettings.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTSettings.xcodeproj; path = "../node_modules/react-native/Libraries/Settings/RCTSettings.xcodeproj"; sourceTree = ""; }; 139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTWebSocket.xcodeproj; path = "../node_modules/react-native/Libraries/WebSocket/RCTWebSocket.xcodeproj"; sourceTree = ""; }; 13B07F961A680F5B00A75B9A /* VideoPlayer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = VideoPlayer.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -316,28 +315,24 @@ 13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = VideoPlayer/Info.plist; sourceTree = ""; }; 13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = VideoPlayer/main.m; sourceTree = ""; }; 146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../node_modules/react-native/React/React.xcodeproj"; sourceTree = ""; }; + 39CBB10045CEBFA9BBB9645E /* libPods-VideoPlayer.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-VideoPlayer.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 5E91572D1DD0AC6500FF2AA8 /* RCTAnimation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAnimation.xcodeproj; path = "../node_modules/react-native/Libraries/NativeAnimation/RCTAnimation.xcodeproj"; sourceTree = ""; }; + 627363E07276C06249D7CEBF /* libPods-VideoPlayer-tvOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-VideoPlayer-tvOS.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = ""; }; 832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = ""; }; 8C2A0F651E25608300E31596 /* RCTVideo.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTVideo.xcodeproj; path = "../node_modules/react-native-video/ios/RCTVideo.xcodeproj"; sourceTree = ""; }; + FA8681CE216D5C6D0010C92A /* VideoPlayer-tvOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "VideoPlayer-tvOS.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + FA8681D0216D5C6E0010C92A /* VideoPlayer-tvOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "VideoPlayer-tvOS.plist"; path = "/Users/amishra/Development/react-native-video-nfb/examples/basic/ios/VideoPlayer-tvOS.plist"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ - 00E356EB1AD99517003FC87E /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 140ED2AC1D01E1AD002B40FF /* libReact.a in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; 13B07F8C1A680F5B00A75B9A /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 8C2A0F841E2560A100E31596 /* libRCTVideo.a in Frameworks */, - 5E9157361DD0AC6A00FF2AA8 /* libRCTAnimation.a in Frameworks */, 146834051AC3E58100842450 /* libReact.a in Frameworks */, + 5E9157361DD0AC6A00FF2AA8 /* libRCTAnimation.a in Frameworks */, + 8C2A0F841E2560A100E31596 /* libRCTVideo.a in Frameworks */, 00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */, 00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */, 00C302E81ABCBA2D00DB3ED1 /* libRCTImage.a in Frameworks */, @@ -350,6 +345,21 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + FA8681BA216D5C6D0010C92A /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + FA8B47A5216D777200AB07CF /* libReact.a in Frameworks */, + FA3566AB216D5D7000E01ABD /* libRCTImage-tvOS.a in Frameworks */, + FA3566AC216D5D7000E01ABD /* libRCTLinking-tvOS.a in Frameworks */, + FA3566AD216D5D7000E01ABD /* libRCTNetwork-tvOS.a in Frameworks */, + FA3566AE216D5D7000E01ABD /* libRCTSettings-tvOS.a in Frameworks */, + FA3566AF216D5D7000E01ABD /* libRCTText-tvOS.a in Frameworks */, + FA3566B0216D5D7000E01ABD /* libRCTWebSocket-tvOS.a in Frameworks */, + FA3566C8216D5DA900E01ABD /* libRCTVideo.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -395,23 +405,6 @@ name = Products; sourceTree = ""; }; - 00E356EF1AD99517003FC87E /* VideoPlayerTests */ = { - isa = PBXGroup; - children = ( - 00E356F21AD99517003FC87E /* VideoPlayerTests.m */, - 00E356F01AD99517003FC87E /* Supporting Files */, - ); - path = VideoPlayerTests; - sourceTree = ""; - }; - 00E356F01AD99517003FC87E /* Supporting Files */ = { - isa = PBXGroup; - children = ( - 00E356F11AD99517003FC87E /* Info.plist */, - ); - name = "Supporting Files"; - sourceTree = ""; - }; 139105B71AF99BAD00B5F7CC /* Products */ = { isa = PBXGroup; children = ( @@ -473,7 +466,7 @@ isa = PBXGroup; children = ( 5E9157331DD0AC6500FF2AA8 /* libRCTAnimation.a */, - 5E9157351DD0AC6500FF2AA8 /* libRCTAnimation-tvOS.a */, + 5E9157351DD0AC6500FF2AA8 /* libRCTAnimation.a */, ); name = Products; sourceTree = ""; @@ -518,10 +511,11 @@ 83CBB9F61A601CBA00E9B192 = { isa = PBXGroup; children = ( + FA8681CF216D5C6D0010C92A /* Resources-iPad */, 13B07FAE1A68108700A75B9A /* VideoPlayer */, 832341AE1AAA6A7D00B99B32 /* Libraries */, - 00E356EF1AD99517003FC87E /* VideoPlayerTests */, 83CBBA001A601CBA00E9B192 /* Products */, + FA35669C216D5D7000E01ABD /* Frameworks */, ); indentWidth = 2; sourceTree = ""; @@ -531,7 +525,7 @@ isa = PBXGroup; children = ( 13B07F961A680F5B00A75B9A /* VideoPlayer.app */, - 00E356EE1AD99517003FC87E /* VideoPlayerTests.xctest */, + FA8681CE216D5C6D0010C92A /* VideoPlayer-tvOS.app */, ); name = Products; sourceTree = ""; @@ -545,27 +539,26 @@ name = Products; sourceTree = ""; }; + FA35669C216D5D7000E01ABD /* Frameworks */ = { + isa = PBXGroup; + children = ( + 39CBB10045CEBFA9BBB9645E /* libPods-VideoPlayer.a */, + 627363E07276C06249D7CEBF /* libPods-VideoPlayer-tvOS.a */, + ); + name = Frameworks; + sourceTree = ""; + }; + FA8681CF216D5C6D0010C92A /* Resources-iPad */ = { + isa = PBXGroup; + children = ( + FA8681D0216D5C6E0010C92A /* VideoPlayer-tvOS.plist */, + ); + name = "Resources-iPad"; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ - 00E356ED1AD99517003FC87E /* VideoPlayerTests */ = { - isa = PBXNativeTarget; - buildConfigurationList = 00E357021AD99517003FC87E /* Build configuration list for PBXNativeTarget "VideoPlayerTests" */; - buildPhases = ( - 00E356EA1AD99517003FC87E /* Sources */, - 00E356EB1AD99517003FC87E /* Frameworks */, - 00E356EC1AD99517003FC87E /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - 00E356F51AD99517003FC87E /* PBXTargetDependency */, - ); - name = VideoPlayerTests; - productName = VideoPlayerTests; - productReference = 00E356EE1AD99517003FC87E /* VideoPlayerTests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; 13B07F861A680F5B00A75B9A /* VideoPlayer */ = { isa = PBXNativeTarget; buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "VideoPlayer" */; @@ -584,6 +577,24 @@ productReference = 13B07F961A680F5B00A75B9A /* VideoPlayer.app */; productType = "com.apple.product-type.application"; }; + FA8681B6216D5C6D0010C92A /* VideoPlayer-tvOS */ = { + isa = PBXNativeTarget; + buildConfigurationList = FA8681CB216D5C6D0010C92A /* Build configuration list for PBXNativeTarget "VideoPlayer-tvOS" */; + buildPhases = ( + FA8681B7216D5C6D0010C92A /* Sources */, + FA8681BA216D5C6D0010C92A /* Frameworks */, + FA8681C7216D5C6D0010C92A /* Resources */, + FA8681CA216D5C6D0010C92A /* Bundle React Native code and images */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "VideoPlayer-tvOS"; + productName = "Hello World"; + productReference = FA8681CE216D5C6D0010C92A /* VideoPlayer-tvOS.app */; + productType = "com.apple.product-type.application"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -592,12 +603,6 @@ attributes = { LastUpgradeCheck = 0610; ORGANIZATIONNAME = Facebook; - TargetAttributes = { - 00E356ED1AD99517003FC87E = { - CreatedOnToolsVersion = 6.2; - TestTargetID = 13B07F861A680F5B00A75B9A; - }; - }; }; buildConfigurationList = 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "VideoPlayer" */; compatibilityVersion = "Xcode 3.2"; @@ -663,7 +668,7 @@ projectRoot = ""; targets = ( 13B07F861A680F5B00A75B9A /* VideoPlayer */, - 00E356ED1AD99517003FC87E /* VideoPlayerTests */, + FA8681B6216D5C6D0010C92A /* VideoPlayer-tvOS */, ); }; /* End PBXProject section */ @@ -823,7 +828,7 @@ remoteRef = 5E9157321DD0AC6500FF2AA8 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - 5E9157351DD0AC6500FF2AA8 /* libRCTAnimation-tvOS.a */ = { + 5E9157351DD0AC6500FF2AA8 /* libRCTAnimation.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; path = libRCTAnimation.a; @@ -931,13 +936,6 @@ /* End PBXReferenceProxy section */ /* Begin PBXResourcesBuildPhase section */ - 00E356EC1AD99517003FC87E /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; 13B07F8E1A680F5B00A75B9A /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -947,6 +945,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + FA8681C7216D5C6D0010C92A /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + FA8681C8216D5C6D0010C92A /* Images.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ @@ -962,19 +968,25 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "export NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh"; + shellScript = "export NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh\n"; + }; + FA8681CA216D5C6D0010C92A /* Bundle React Native code and images */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Bundle React Native code and images"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "export NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh\n"; }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ - 00E356EA1AD99517003FC87E /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 00E356F31AD99517003FC87E /* VideoPlayerTests.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; 13B07F871A680F5B00A75B9A /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -984,15 +996,16 @@ ); runOnlyForDeploymentPostprocessing = 0; }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXTargetDependency section */ - 00E356F51AD99517003FC87E /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = 13B07F861A680F5B00A75B9A /* VideoPlayer */; - targetProxy = 00E356F41AD99517003FC87E /* PBXContainerItemProxy */; + FA8681B7216D5C6D0010C92A /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + FA8681B8216D5C6D0010C92A /* AppDelegate.m in Sources */, + FA8681B9216D5C6D0010C92A /* main.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; }; -/* End PBXTargetDependency section */ +/* End PBXSourcesBuildPhase section */ /* Begin PBXVariantGroup section */ 13B07FB11A68108700A75B9A /* LaunchScreen.xib */ = { @@ -1007,41 +1020,13 @@ /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ - 00E356F61AD99517003FC87E /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - BUNDLE_LOADER = "$(TEST_HOST)"; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - INFOPLIST_FILE = VideoPlayerTests/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_NAME = "$(TARGET_NAME)"; - TEST_HOST = "$(BUILT_PRODUCTS_DIR)/VideoPlayer.app/VideoPlayer"; - }; - name = Debug; - }; - 00E356F71AD99517003FC87E /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - BUNDLE_LOADER = "$(TEST_HOST)"; - COPY_PHASE_STRIP = NO; - INFOPLIST_FILE = VideoPlayerTests/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_NAME = "$(TARGET_NAME)"; - TEST_HOST = "$(BUILT_PRODUCTS_DIR)/VideoPlayer.app/VideoPlayer"; - }; - name = Release; - }; 13B07F941A680F5B00A75B9A /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CURRENT_PROJECT_VERSION = 1; DEAD_CODE_STRIPPING = NO; + HEADER_SEARCH_PATHS = "$(inherited)"; INFOPLIST_FILE = VideoPlayer/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; OTHER_LDFLAGS = ( @@ -1059,6 +1044,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CURRENT_PROJECT_VERSION = 1; + HEADER_SEARCH_PATHS = "$(inherited)"; INFOPLIST_FILE = VideoPlayer/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; OTHER_LDFLAGS = ( @@ -1147,18 +1133,54 @@ }; name = Release; }; + FA8681CC216D5C6D0010C92A /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CURRENT_PROJECT_VERSION = 1; + DEAD_CODE_STRIPPING = NO; + INFOPLIST_FILE = "VideoPlayer-tvOS.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + OTHER_LDFLAGS = ( + "$(inherited)", + "-ObjC", + "-lc++", + ); + PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.VideoPlayer-tvOS"; + PRODUCT_NAME = "VideoPlayer-tvOS"; + SDKROOT = appletvos; + SUPPORTED_PLATFORMS = "appletvsimulator appletvos"; + TARGETED_DEVICE_FAMILY = 3; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Debug; + }; + FA8681CD216D5C6D0010C92A /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CURRENT_PROJECT_VERSION = 1; + INFOPLIST_FILE = "VideoPlayer-tvOS.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + OTHER_LDFLAGS = ( + "$(inherited)", + "-ObjC", + "-lc++", + ); + PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.VideoPlayer-tvOS"; + PRODUCT_NAME = "VideoPlayer-tvOS"; + SDKROOT = appletvos; + SUPPORTED_PLATFORMS = "appletvsimulator appletvos"; + TARGETED_DEVICE_FAMILY = 3; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Release; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ - 00E357021AD99517003FC87E /* Build configuration list for PBXNativeTarget "VideoPlayerTests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 00E356F61AD99517003FC87E /* Debug */, - 00E356F71AD99517003FC87E /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "VideoPlayer" */ = { isa = XCConfigurationList; buildConfigurations = ( @@ -1177,6 +1199,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + FA8681CB216D5C6D0010C92A /* Build configuration list for PBXNativeTarget "VideoPlayer-tvOS" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + FA8681CC216D5C6D0010C92A /* Debug */, + FA8681CD216D5C6D0010C92A /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; /* End XCConfigurationList section */ }; rootObject = 83CBB9F71A601CBA00E9B192 /* Project object */; diff --git a/examples/basic/ios/VideoPlayer.xcodeproj/xcshareddata/xcschemes/VideoPlayer-tvOS.xcscheme b/examples/basic/ios/VideoPlayer.xcodeproj/xcshareddata/xcschemes/VideoPlayer-tvOS.xcscheme new file mode 100644 index 00000000..75b3d2eb --- /dev/null +++ b/examples/basic/ios/VideoPlayer.xcodeproj/xcshareddata/xcschemes/VideoPlayer-tvOS.xcscheme @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/basic/ios/VideoPlayer.xcodeproj/xcshareddata/xcschemes/VideoPlayer.xcscheme b/examples/basic/ios/VideoPlayer.xcodeproj/xcshareddata/xcschemes/VideoPlayer.xcscheme index f27978d8..48a64467 100644 --- a/examples/basic/ios/VideoPlayer.xcodeproj/xcshareddata/xcschemes/VideoPlayer.xcscheme +++ b/examples/basic/ios/VideoPlayer.xcodeproj/xcshareddata/xcschemes/VideoPlayer.xcscheme @@ -34,20 +34,6 @@ ReferencedContainer = "container:VideoPlayer.xcodeproj"> - - - - - - - - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - BNDL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1 - - diff --git a/examples/basic/ios/VideoPlayerTests/VideoPlayerTests.m b/examples/basic/ios/VideoPlayerTests/VideoPlayerTests.m deleted file mode 100644 index 9b7b412d..00000000 --- a/examples/basic/ios/VideoPlayerTests/VideoPlayerTests.m +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -#import -#import - -#import -#import - -#define TIMEOUT_SECONDS 600 -#define TEXT_TO_LOOK_FOR @"Welcome to React Native!" - -@interface VideoPlayerTests : XCTestCase - -@end - -@implementation VideoPlayerTests - -- (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test -{ - if (test(view)) { - return YES; - } - for (UIView *subview in [view subviews]) { - if ([self findSubviewInView:subview matching:test]) { - return YES; - } - } - return NO; -} - -- (void)testRendersWelcomeScreen -{ - UIViewController *vc = [[[[UIApplication sharedApplication] delegate] window] rootViewController]; - NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; - BOOL foundElement = NO; - - __block NSString *redboxError = nil; - RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) { - if (level >= RCTLogLevelError) { - redboxError = message; - } - }); - - while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) { - [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; - [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; - - foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) { - if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) { - return YES; - } - return NO; - }]; - } - - RCTSetLogFunction(RCTDefaultLogFunction); - - XCTAssertNil(redboxError, @"RedBox error: %@", redboxError); - XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS); -} - - -@end diff --git a/ios/Video/RCTVideo.h b/ios/Video/RCTVideo.h index b2296c5d..e43fbe50 100644 --- a/ios/Video/RCTVideo.h +++ b/ios/Video/RCTVideo.h @@ -1,9 +1,9 @@ -#import #import #import "AVKit/AVKit.h" #import "UIView+FindUIViewController.h" #import "RCTVideoPlayerViewController.h" #import "RCTVideoPlayerViewControllerDelegate.h" +#import #if __has_include() #import @@ -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; diff --git a/ios/Video/RCTVideo.m b/ios/Video/RCTVideo.m index 9fe30b63..61b87578 100644 --- a/ios/Video/RCTVideo.m +++ b/ios/Video/RCTVideo.m @@ -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; @@ -29,14 +30,15 @@ static int const RCTVideoUnset = -1; BOOL _playerBufferEmpty; AVPlayerLayer *_playerLayer; BOOL _playerLayerObserverSet; - AVPlayerViewController *_playerViewController; + RCTVideoPlayerViewController *_playerViewController; NSURL *_videoURL; /* Required to publish events */ RCTEventDispatcher *_eventDispatcher; BOOL _playbackRateObserverRegistered; + BOOL _isExternalPlaybackActiveObserverRegistered; BOOL _videoLoadStarted; - + bool _pendingSeek; float _pendingSeekTime; float _lastSeekTime; @@ -61,6 +63,8 @@ static int const RCTVideoUnset = -1; BOOL _playWhenInactive; NSString * _ignoreSilentSwitch; NSString * _resizeMode; + BOOL _fullscreen; + NSString * _fullscreenOrientation; BOOL _fullscreenPlayerPresented; UIViewController * _presentingViewController; #if __has_include() @@ -74,10 +78,12 @@ static int const RCTVideoUnset = -1; _eventDispatcher = eventDispatcher; _playbackRateObserverRegistered = NO; + _isExternalPlaybackActiveObserverRegistered = NO; _playbackStalled = NO; _rate = 1.0; _volume = 1.0; _resizeMode = @"AVLayerVideoGravityResizeAspectFill"; + _fullscreenOrientation = @"all"; _pendingSeek = false; _pendingSeekTime = 0.0f; _lastSeekTime = 0.0f; @@ -105,7 +111,7 @@ static int const RCTVideoUnset = -1; selector:@selector(applicationWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil]; - + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioRouteChanged:) name:AVAudioSessionRouteChangeNotification @@ -115,14 +121,17 @@ static int const RCTVideoUnset = -1; return self; } -- (AVPlayerViewController*)createPlayerViewController:(AVPlayer*)player withPlayerItem:(AVPlayerItem*)playerItem { - RCTVideoPlayerViewController* playerLayer= [[RCTVideoPlayerViewController alloc] init]; - playerLayer.showsPlaybackControls = YES; - playerLayer.rctDelegate = self; - playerLayer.view.frame = self.bounds; - playerLayer.player = player; - playerLayer.view.frame = self.bounds; - return playerLayer; +- (RCTVideoPlayerViewController*)createPlayerViewController:(AVPlayer*)player + withPlayerItem:(AVPlayerItem*)playerItem { + RCTVideoPlayerViewController* viewController = [[RCTVideoPlayerViewController alloc] init]; + viewController.showsPlaybackControls = YES; + viewController.rctDelegate = self; + viewController.preferredOrientation = _fullscreenOrientation; + + viewController.view.frame = self.bounds; + viewController.player = player; + viewController.view.frame = self.bounds; + return viewController; } /* --------------------------------------------------------- @@ -216,7 +225,7 @@ static int const RCTVideoUnset = -1; NSNumber *reason = [[notification userInfo] objectForKey:AVAudioSessionRouteChangeReasonKey]; NSNumber *previousRoute = [[notification userInfo] objectForKey:AVAudioSessionRouteChangePreviousRouteKey]; if (reason.unsignedIntValue == AVAudioSessionRouteChangeReasonOldDeviceUnavailable) { - self.onVideoAudioBecomingNoisy(@{@"target": self.reactTag}); + self.onVideoAudioBecomingNoisy(@{@"target": self.reactTag}); } } @@ -333,15 +342,22 @@ 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]; - + //Perform on next run loop, otherwise onVideoLoadStart is nil if (self.onVideoLoadStart) { id uri = [source objectForKey:@"uri"]; @@ -363,7 +379,7 @@ static int const RCTVideoUnset = -1; return [NSURL URLWithString:filepath]; } - // code to support local caching + // if no file found, check if the file exists in the Document directory NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString* relativeFilePath = [filepath lastPathComponent]; // the file may be multiple levels below the documents directory @@ -395,14 +411,14 @@ static int const RCTVideoUnset = -1; ofTrack:videoAsset atTime:kCMTimeZero error:nil]; - + AVAssetTrack *audioAsset = [asset tracksWithMediaType:AVMediaTypeAudio].firstObject; AVMutableCompositionTrack *audioCompTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid]; [audioCompTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.timeRange.duration) ofTrack:audioAsset atTime:kCMTimeZero error:nil]; - + NSMutableArray* validTextTracks = [NSMutableArray array]; for (int i = 0; i < _textTracks.count; ++i) { AVURLAsset *textURLAsset; @@ -419,9 +435,9 @@ static int const RCTVideoUnset = -1; addMutableTrackWithMediaType:AVMediaTypeText preferredTrackID:kCMPersistentTrackID_Invalid]; [textCompTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.timeRange.duration) - ofTrack:textTrackAsset - atTime:kCMTimeZero - error:nil]; + ofTrack:textTrackAsset + atTime:kCMTimeZero + error:nil]; } if (validTextTracks.count != _textTracks.count) { [self setTextTracks:validTextTracks]; @@ -646,6 +662,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]; } @@ -661,7 +683,7 @@ static int const RCTVideoUnset = -1; selector:@selector(playerItemDidReachEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:[_player currentItem]]; - + [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemPlaybackStalledNotification object:nil]; @@ -833,7 +855,7 @@ static int const RCTVideoUnset = -1; [_player setVolume:_volume]; [_player setMuted:NO]; } - + [self setSelectedAudioTrack:_selectedAudioTrack]; [self setSelectedTextTrack:_selectedTextTrack]; [self setResizeMode:_resizeMode]; @@ -854,40 +876,40 @@ static int const RCTVideoUnset = -1; AVMediaSelectionGroup *group = [_player.currentItem.asset mediaSelectionGroupForMediaCharacteristic:characteristic]; AVMediaSelectionOption *mediaOption; - + if ([type isEqualToString:@"disabled"]) { - // Do nothing. We want to ensure option is nil + // Do nothing. We want to ensure option is nil } else if ([type isEqualToString:@"language"] || [type isEqualToString:@"title"]) { NSString *value = criteria[@"value"]; for (int i = 0; i < group.options.count; ++i) { AVMediaSelectionOption *currentOption = [group.options objectAtIndex:i]; NSString *optionValue; if ([type isEqualToString:@"language"]) { - optionValue = [currentOption extendedLanguageTag]; + optionValue = [currentOption extendedLanguageTag]; } else { - optionValue = [[[currentOption commonMetadata] - valueForKey:@"value"] - objectAtIndex:0]; + optionValue = [[[currentOption commonMetadata] + valueForKey:@"value"] + objectAtIndex:0]; } if ([value isEqualToString:optionValue]) { - mediaOption = currentOption; - break; + mediaOption = currentOption; + break; } - } - //} else if ([type isEqualToString:@"default"]) { - // option = group.defaultOption; */ + } + //} else if ([type isEqualToString:@"default"]) { + // option = group.defaultOption; */ } else if ([type isEqualToString:@"index"]) { if ([criteria[@"value"] isKindOfClass:[NSNumber class]]) { - int index = [criteria[@"value"] intValue]; - if (group.options.count > index) { - mediaOption = [group.options objectAtIndex:index]; - } + int index = [criteria[@"value"] intValue]; + if (group.options.count > index) { + mediaOption = [group.options objectAtIndex:index]; + } } } else { // default. invalid type or "system" - [_player.currentItem selectMediaOptionAutomaticallyInMediaSelectionGroup:group]; - return; + [_player.currentItem selectMediaOptionAutomaticallyInMediaSelectionGroup:group]; + return; } - + // If a match isn't found, option will be nil and text tracks will be disabled [_player.currentItem selectMediaOption:mediaOption inMediaSelectionGroup:group]; } @@ -895,7 +917,7 @@ static int const RCTVideoUnset = -1; - (void)setSelectedAudioTrack:(NSDictionary *)selectedAudioTrack { _selectedAudioTrack = selectedAudioTrack; [self setMediaSelectionTrackForCharacteristic:AVMediaCharacteristicAudible - withCriteria:_selectedAudioTrack]; + withCriteria:_selectedAudioTrack]; } - (void)setSelectedTextTrack:(NSDictionary *)selectedTextTrack { @@ -967,7 +989,7 @@ static int const RCTVideoUnset = -1; } } } - + for (int i = firstTextIndex; i < _player.currentItem.tracks.count; ++i) { BOOL isEnabled = NO; if (selectedTrackIndex != RCTVideoUnset) { @@ -1023,7 +1045,7 @@ static int const RCTVideoUnset = -1; - (void)setTextTracks:(NSArray*) textTracks; { _textTracks = textTracks; - + // in case textTracks was set after selectedTextTrack if (_selectedTextTrack) [self setSelectedTextTrack:_selectedTextTrack]; } @@ -1038,14 +1060,14 @@ static int const RCTVideoUnset = -1; NSString *title = @""; NSArray *values = [[currentOption commonMetadata] valueForKey:@"value"]; if (values.count > 0) { - title = [values objectAtIndex:0]; + title = [values objectAtIndex:0]; } NSString *language = [currentOption extendedLanguageTag] ? [currentOption extendedLanguageTag] : @""; NSDictionary *audioTrack = @{ - @"index": [NSNumber numberWithInt:i], - @"title": title, - @"language": language - }; + @"index": [NSNumber numberWithInt:i], + @"title": title, + @"language": language + }; [audioTracks addObject:audioTrack]; } return audioTracks; @@ -1083,9 +1105,8 @@ static int const RCTVideoUnset = -1; return _fullscreenPlayerPresented; } -- (void)setFullscreen:(BOOL)fullscreen -{ - if( fullscreen && !_fullscreenPlayerPresented ) +- (void)setFullscreen:(BOOL) fullscreen { + if( fullscreen && !_fullscreenPlayerPresented && _player ) { // Ensure player view controller is not null if( !_playerViewController ) @@ -1130,6 +1151,13 @@ static int const RCTVideoUnset = -1; } } +- (void)setFullscreenOrientation:(NSString *)orientation { + _fullscreenOrientation = orientation; + if (_fullscreenPlayerPresented) { + _playerViewController.preferredOrientation = orientation; + } +} + - (void)usePlayerViewController { if( _player ) @@ -1183,7 +1211,7 @@ static int const RCTVideoUnset = -1; - (void)setProgressUpdateInterval:(float)progressUpdateInterval { _progressUpdateInterval = progressUpdateInterval; - + if (_timeObserver) { [self removePlayerTimeObserver]; [self addPlayerTimeObserver]; @@ -1290,6 +1318,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]; diff --git a/ios/Video/RCTVideoManager.m b/ios/Video/RCTVideoManager.m index e0e0162e..aa3c4670 100644 --- a/ios/Video/RCTVideoManager.m +++ b/ios/Video/RCTVideoManager.m @@ -37,6 +37,7 @@ RCT_EXPORT_VIEW_PROPERTY(rate, float); RCT_EXPORT_VIEW_PROPERTY(seek, NSDictionary); RCT_EXPORT_VIEW_PROPERTY(currentTime, float); RCT_EXPORT_VIEW_PROPERTY(fullscreen, BOOL); +RCT_EXPORT_VIEW_PROPERTY(fullscreenOrientation, NSString); RCT_EXPORT_VIEW_PROPERTY(progressUpdateInterval, float); /* Should support: onLoadStart, onLoad, and onError to stay consistent with Image */ RCT_EXPORT_VIEW_PROPERTY(onVideoLoadStart, RCTBubblingEventBlock); @@ -56,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 { diff --git a/ios/Video/RCTVideoPlayerViewController.h b/ios/Video/RCTVideoPlayerViewController.h index d427b63d..99b1349b 100644 --- a/ios/Video/RCTVideoPlayerViewController.h +++ b/ios/Video/RCTVideoPlayerViewController.h @@ -12,4 +12,8 @@ @interface RCTVideoPlayerViewController : AVPlayerViewController @property (nonatomic, weak) id rctDelegate; + +// Optional paramters +@property (nonatomic, weak) NSString* preferredOrientation; + @end diff --git a/ios/Video/RCTVideoPlayerViewController.m b/ios/Video/RCTVideoPlayerViewController.m index 7809221a..e9550db5 100644 --- a/ios/Video/RCTVideoPlayerViewController.m +++ b/ios/Video/RCTVideoPlayerViewController.m @@ -6,6 +6,13 @@ @implementation RCTVideoPlayerViewController +- (BOOL)shouldAutorotate { + if (self.preferredOrientation.lowercaseString == nil || [self.preferredOrientation.lowercaseString isEqualToString:@"all"]) + return YES; + + return NO; +} + - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; @@ -13,4 +20,23 @@ [_rctDelegate videoPlayerViewControllerDidDismiss:self]; } +#if !TARGET_OS_TV +- (UIInterfaceOrientationMask)supportedInterfaceOrientations { + return UIInterfaceOrientationMaskAll; +} + +- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { + if ([self.preferredOrientation.lowercaseString isEqualToString:@"landscape"]) { + return UIInterfaceOrientationLandscapeRight; + } + else if ([self.preferredOrientation.lowercaseString isEqualToString:@"portrait"]) { + return UIInterfaceOrientationPortrait; + } + else { // default case + UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; + return orientation; + } +} +#endif + @end diff --git a/package.json b/package.json index 3051b567..92366be3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-video", - "version": "3.2.0", + "version": "3.2.1", "description": "A