Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manual cache experiment #10

Open
wants to merge 18 commits into
base: manual-cache
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
216 changes: 118 additions & 98 deletions CHANGELOG.md

Large diffs are not rendered by default.

754 changes: 445 additions & 309 deletions README.md

Large diffs are not rendered by default.

114 changes: 56 additions & 58 deletions Video.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ViewPropTypes,
Image,
Platform,
findNodeHandle
findNodeHandle,
} from "react-native";
import resolveAssetSource from "react-native/Libraries/Image/resolveAssetSource";
import TextTrackType from "./TextTrackType";
Expand All @@ -17,27 +17,25 @@ import VideoResizeMode from "./VideoResizeMode.js";

const styles = StyleSheet.create({
base: {
overflow: "hidden"
}
overflow: "hidden",
},
});

const { ExoPlayerCache } = NativeModules;
const { ExoPlayerExpCache } = NativeModules;

export { TextTrackType, FilterType, ExoPlayerCache };
export { TextTrackType, FilterType, ExoPlayerExpCache };

export default class Video extends Component {
constructor(props) {
super(props);

this.state = {
showPoster: !!props.poster
showPoster: !!props.poster,
};
}

static export = async (url) => {
return await NativeModules.VideoManager.export(
url,
);
return await NativeModules.VideoEManager.export(url);
};

setNativeProps(nativeProps) {
Expand All @@ -59,7 +57,7 @@ export default class Video extends Component {
stringsOnlyObject(obj) {
const strObj = {};

Object.keys(obj).forEach(x => {
Object.keys(obj).forEach((x) => {
strObj[x] = this.toTypeString(obj[x]);
});

Expand All @@ -73,42 +71,42 @@ export default class Video extends Component {
this.setNativeProps({
seek: {
time,
tolerance
}
tolerance,
},
});
} else {
this.setNativeProps({
seek: time
seek: time,
});
}
};

presentFullscreenPlayer = () => {
this.setNativeProps({
fullscreen: true
fullscreen: true,
});
};

dismissFullscreenPlayer = () => {
this.setNativeProps({
fullscreen: false
fullscreen: false,
});
};

save = async (options?) => {
return await NativeModules.VideoManager.save(
return await NativeModules.VideoEManager.save(
options,
findNodeHandle(this._root)
);
};

restoreUserInterfaceForPictureInPictureStopCompleted = restored => {
restoreUserInterfaceForPictureInPictureStopCompleted = (restored) => {
this.setNativeProps({
restoreUserInterfaceForPIPStopCompletionHandler: restored
restoreUserInterfaceForPIPStopCompletionHandler: restored,
});
};

_assignRoot = component => {
_assignRoot = (component) => {
this._root = component;
};

Expand All @@ -118,13 +116,13 @@ export default class Video extends Component {
}
};

_onLoadStart = event => {
_onLoadStart = (event) => {
if (this.props.onLoadStart) {
this.props.onLoadStart(event.nativeEvent);
}
};

_onLoad = event => {
_onLoad = (event) => {
// Need to hide poster here for windows as onReadyForDisplay is not implemented
if (Platform.OS === "windows") {
this._hidePoster();
Expand All @@ -134,67 +132,67 @@ export default class Video extends Component {
}
};

_onError = event => {
_onError = (event) => {
if (this.props.onError) {
this.props.onError(event.nativeEvent);
}
};

_onProgress = event => {
_onProgress = (event) => {
if (this.props.onProgress) {
this.props.onProgress(event.nativeEvent);
}
};

_onBandwidthUpdate = event => {
_onBandwidthUpdate = (event) => {
if (this.props.onBandwidthUpdate) {
this.props.onBandwidthUpdate(event.nativeEvent);
}
};

_onSeek = event => {
_onSeek = (event) => {
if (this.props.onSeek) {
this.props.onSeek(event.nativeEvent);
}
};

_onEnd = event => {
_onEnd = (event) => {
if (this.props.onEnd) {
this.props.onEnd(event.nativeEvent);
}
};

_onTimedMetadata = event => {
_onTimedMetadata = (event) => {
if (this.props.onTimedMetadata) {
this.props.onTimedMetadata(event.nativeEvent);
}
};

_onFullscreenPlayerWillPresent = event => {
_onFullscreenPlayerWillPresent = (event) => {
if (this.props.onFullscreenPlayerWillPresent) {
this.props.onFullscreenPlayerWillPresent(event.nativeEvent);
}
};

_onFullscreenPlayerDidPresent = event => {
_onFullscreenPlayerDidPresent = (event) => {
if (this.props.onFullscreenPlayerDidPresent) {
this.props.onFullscreenPlayerDidPresent(event.nativeEvent);
}
};

_onFullscreenPlayerWillDismiss = event => {
_onFullscreenPlayerWillDismiss = (event) => {
if (this.props.onFullscreenPlayerWillDismiss) {
this.props.onFullscreenPlayerWillDismiss(event.nativeEvent);
}
};

_onFullscreenPlayerDidDismiss = event => {
_onFullscreenPlayerDidDismiss = (event) => {
if (this.props.onFullscreenPlayerDidDismiss) {
this.props.onFullscreenPlayerDidDismiss(event.nativeEvent);
}
};

_onReadyForDisplay = event => {
_onReadyForDisplay = (event) => {
if (!this.props.audioOnly) {
this._hidePoster();
}
Expand All @@ -204,25 +202,25 @@ export default class Video extends Component {
}
};

_onPlaybackStalled = event => {
_onPlaybackStalled = (event) => {
if (this.props.onPlaybackStalled) {
this.props.onPlaybackStalled(event.nativeEvent);
}
};

_onPlaybackResume = event => {
_onPlaybackResume = (event) => {
if (this.props.onPlaybackResume) {
this.props.onPlaybackResume(event.nativeEvent);
}
};

_onPlaybackRateChange = event => {
_onPlaybackRateChange = (event) => {
if (this.props.onPlaybackRateChange) {
this.props.onPlaybackRateChange(event.nativeEvent);
}
};

_onExternalPlaybackChange = event => {
_onExternalPlaybackChange = (event) => {
if (this.props.onExternalPlaybackChange) {
this.props.onExternalPlaybackChange(event.nativeEvent);
}
Expand All @@ -234,31 +232,31 @@ export default class Video extends Component {
}
};

_onPictureInPictureStatusChanged = event => {
_onPictureInPictureStatusChanged = (event) => {
if (this.props.onPictureInPictureStatusChanged) {
this.props.onPictureInPictureStatusChanged(event.nativeEvent);
}
};

_onRestoreUserInterfaceForPictureInPictureStop = event => {
_onRestoreUserInterfaceForPictureInPictureStop = (event) => {
if (this.props.onRestoreUserInterfaceForPictureInPictureStop) {
this.props.onRestoreUserInterfaceForPictureInPictureStop();
}
};

_onAudioFocusChanged = event => {
_onAudioFocusChanged = (event) => {
if (this.props.onAudioFocusChanged) {
this.props.onAudioFocusChanged(event.nativeEvent);
}
};

_onBuffer = event => {
_onBuffer = (event) => {
if (this.props.onBuffer) {
this.props.onBuffer(event.nativeEvent);
}
};

getViewManagerConfig = viewManagerName => {
getViewManagerConfig = (viewManagerName) => {
if (!NativeModules.UIManager.getViewManagerConfig) {
return NativeModules.UIManager[viewManagerName];
}
Expand Down Expand Up @@ -288,7 +286,7 @@ export default class Video extends Component {
);

let nativeResizeMode;
const RCTVideoInstance = this.getViewManagerConfig("RCTVideo");
const RCTVideoInstance = this.getViewManagerConfig("RCTVideoE");

if (resizeMode === VideoResizeMode.stretch) {
nativeResizeMode = RCTVideoInstance.Constants.ScaleToFill;
Expand All @@ -314,7 +312,7 @@ export default class Video extends Component {
patchVer: source.patchVer || 0,
requestHeaders: source.headers
? this.stringsOnlyObject(source.headers)
: {}
: {},
},
onVideoLoadStart: this._onLoadStart,
onVideoLoad: this._onLoad,
Expand All @@ -339,12 +337,12 @@ export default class Video extends Component {
onAudioBecomingNoisy: this._onAudioBecomingNoisy,
onPictureInPictureStatusChanged: this._onPictureInPictureStatusChanged,
onRestoreUserInterfaceForPictureInPictureStop: this
._onRestoreUserInterfaceForPictureInPictureStop
._onRestoreUserInterfaceForPictureInPictureStop,
});

const posterStyle = {
...StyleSheet.absoluteFillObject,
resizeMode: this.props.posterResizeMode || "contain"
resizeMode: this.props.posterResizeMode || "contain",
};

return (
Expand Down Expand Up @@ -379,7 +377,7 @@ Video.propTypes = {
FilterType.PROCESS,
FilterType.TONAL,
FilterType.TRANSFER,
FilterType.SEPIA
FilterType.SEPIA,
]),
filterEnabled: PropTypes.bool,
/* Native only */
Expand All @@ -405,10 +403,10 @@ Video.propTypes = {
/* Wrapper component */
source: PropTypes.oneOfType([
PropTypes.shape({
uri: PropTypes.string
uri: PropTypes.string,
}),
// Opaque type returned by require('./video.mp4')
PropTypes.number
PropTypes.number,
]),
minLoadRetryCount: PropTypes.number,
maxBitRate: PropTypes.number,
Expand All @@ -420,15 +418,15 @@ Video.propTypes = {
allowsExternalPlayback: PropTypes.bool,
selectedAudioTrack: PropTypes.shape({
type: PropTypes.string.isRequired,
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
}),
selectedVideoTrack: PropTypes.shape({
type: PropTypes.string.isRequired,
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
}),
selectedTextTrack: PropTypes.shape({
type: PropTypes.string.isRequired,
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
}),
textTracks: PropTypes.arrayOf(
PropTypes.shape({
Expand All @@ -437,9 +435,9 @@ Video.propTypes = {
type: PropTypes.oneOf([
TextTrackType.SRT,
TextTrackType.TTML,
TextTrackType.VTT
TextTrackType.VTT,
]),
language: PropTypes.string.isRequired
language: PropTypes.string.isRequired,
})
),
paused: PropTypes.bool,
Expand All @@ -449,7 +447,7 @@ Video.propTypes = {
minBufferMs: PropTypes.number,
maxBufferMs: PropTypes.number,
bufferForPlaybackMs: PropTypes.number,
bufferForPlaybackAfterRebufferMs: PropTypes.number
bufferForPlaybackAfterRebufferMs: PropTypes.number,
}),
stereoPan: PropTypes.number,
rate: PropTypes.number,
Expand Down Expand Up @@ -495,13 +493,13 @@ Video.propTypes = {
translateX: PropTypes.number,
translateY: PropTypes.number,
rotation: PropTypes.number,
...ViewPropTypes
...ViewPropTypes,
};

const RCTVideo = requireNativeComponent("RCTVideo", Video, {
const RCTVideo = requireNativeComponent("RCTVideoE", Video, {
nativeOnly: {
src: true,
seek: true,
fullscreen: true
}
fullscreen: true,
},
});
4 changes: 2 additions & 2 deletions android-exoplayer/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
## react-native-video - ExoPlayer
## react-native-video-exp - ExoPlayer

This is an Android React Native video component based on ExoPlayer v2.

> ExoPlayer is an application level media player for Android. It provides an alternative to Android’s MediaPlayer API for playing audio and video both locally and over the Internet. ExoPlayer supports features not currently supported by Android’s MediaPlayer API, including DASH and SmoothStreaming adaptive playbacks. Unlike the MediaPlayer API, ExoPlayer is easy to customize and extend, and can be updated through Play Store application updates.

https://github.com/google/ExoPlayer

## Benefits over `[email protected]`:
## Benefits over `react-native-video-exp@0.9.0`:

- Android Video library built by Google, with a lot of support
- Supports DASH, HlS, & SmoothStreaming adaptive streams
Expand Down
2 changes: 1 addition & 1 deletion android-exoplayer/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.brentvatne.react">
package="com.brentvatne_exp.react">
</manifest>
Loading