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

fix: omit packager assets from caching #1438

Merged
merged 4 commits into from
Jan 24, 2019
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

### next

* Fix loading package resolved videos when using video-caching [#1438](https://github.com/react-native-community/react-native-video/pull/1438)

### Version 4.3.0
* Fix iOS video not displaying after switching source [#1395](https://github.com/react-native-community/react-native-video/pull/1395)
* Add the filterEnabled flag, fixes iOS video start time regression [#1384](https://github.com/react-native-community/react-native-video/pull/1384)
Expand Down
2 changes: 2 additions & 0 deletions Video.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export default class Video extends Component {
render() {
const resizeMode = this.props.resizeMode;
const source = resolveAssetSource(this.props.source) || {};
const shouldCache = !Boolean(source.__packager_asset)

let uri = source.uri || '';
if (uri && uri.match(/^\//)) {
Expand Down Expand Up @@ -241,6 +242,7 @@ export default class Video extends Component {
uri,
isNetwork,
isAsset,
shouldCache,
type: source.type || '',
mainVer: source.mainVer || 0,
patchVer: source.patchVer || 0,
Expand Down
78 changes: 58 additions & 20 deletions examples/video-caching/App.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,70 @@
*/

import React, { Component } from "react";
import { StyleSheet, Text, View, Dimensions, TouchableOpacity } from "react-native";
import { Alert, StyleSheet, Text, View, Dimensions, TouchableOpacity } from "react-native";
import Video from "react-native-video";

const { height, width } = Dimensions.get("screen");

type Props = {};
export default class App extends Component<Props> {

type State = {
showLocal: boolean
};

function Button({ text, onPress }: { text: string, onPress: () => void }) {
return (
<TouchableOpacity
onPress={onPress}
style={styles.button}
>
<Text style={{color: 'white'}}>{text}</Text>
</TouchableOpacity>
)
}

export default class App extends Component<Props, State> {
state = {
showLocal: false
}
render() {
return (
<View style={styles.container}>
<Video
source={{
uri:
"https://rawgit.com/mediaelement/mediaelement-files/master/big_buck_bunny.mp4"
}}
source={
this.state.showLocal ?
require('../basic/broadchurch.mp4') :
{
uri: "https://rawgit.com/mediaelement/mediaelement-files/master/big_buck_bunny.mp4"
}
}
ref={player => {
this.player = player;
}}
onEnd={() => {
this.player.seek(0);
}}
onError={(err) => {
Alert.alert(JSON.stringify(err))
}}
style={{ flex: 1, height, width }}
/>
<TouchableOpacity
onPress={async () => {
let response = await this.player.save();
let uri = response.uri;
console.log("Download URI", uri);
}}
style={styles.button}
>
<Text style={{color: 'white'}}>Save</Text>
</TouchableOpacity>
<View style={styles.absoluteOverlay}>
<Button
onPress={async () => {
let response = await this.player.save();
let uri = response.uri;
console.warn("Download URI", uri);
}}
text="Save"
/>
<Button
onPress={() => {
this.setState(state => ({ showLocal: !state.showLocal }))
}}
text={this.state.showLocal ? "Show Remote" : "Show Local"}
/>
</View>
</View>
);
}
Expand All @@ -50,13 +81,20 @@ const styles = StyleSheet.create({
alignItems: "center",
backgroundColor: "#F5FCFF"
},
button: {
absoluteOverlay: {
flexDirection: 'row',
position: 'absolute',
top: 50,
right: 16,
top: 0,
width: '100%',
marginTop: 50,
},
button: {
padding: 10,
backgroundColor: '#9B2FAE',
borderRadius: 8
borderRadius: 8,
flex: 1,
alignItems: 'center',
marginHorizontal: 5,
},
welcome: {
fontSize: 20,
Expand Down
2 changes: 1 addition & 1 deletion examples/video-caching/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ target 'VideoCaching' do
'DevSupport'
]

pod 'react-native-video/VideoCaching', :path => '../node_modules/react-native-video/react-native-video.podspec'
pod 'react-native-video/VideoCaching', :path => '../../../react-native-video.podspec'
end
10 changes: 5 additions & 5 deletions examples/video-caching/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ PODS:
- glog (0.3.4)
- React (0.56.0):
- React/Core (= 0.56.0)
- react-native-video/Video (3.2.2):
- react-native-video/Video (4.3.1):
- React
- react-native-video/VideoCaching (3.2.2):
- react-native-video/VideoCaching (4.3.1):
- DVAssetLoaderDelegate (~> 0.3.1)
- React
- react-native-video/Video
Expand Down Expand Up @@ -73,7 +73,7 @@ DEPENDENCIES:
- DoubleConversion (from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`)
- Folly (from `../node_modules/react-native/third-party-podspecs/Folly.podspec`)
- glog (from `../node_modules/react-native/third-party-podspecs/GLog.podspec`)
- react-native-video/VideoCaching (from `../node_modules/react-native-video/react-native-video.podspec`)
- react-native-video/VideoCaching (from `../../../react-native-video.podspec`)
- React/Core (from `../node_modules/react-native`)
- React/CxxBridge (from `../node_modules/react-native`)
- React/DevSupport (from `../node_modules/react-native`)
Expand Down Expand Up @@ -108,7 +108,7 @@ EXTERNAL SOURCES:
React:
:path: "../node_modules/react-native"
react-native-video:
:path: "../node_modules/react-native-video/react-native-video.podspec"
:path: "../../../react-native-video.podspec"
yoga:
:path: "../node_modules/react-native/ReactCommon/yoga/yoga.podspec"

Expand All @@ -123,6 +123,6 @@ SPEC CHECKSUMS:
SPTPersistentCache: df36ea46762d7cf026502bbb86a8b79d0080dff4
yoga: b1ce48b6cf950b98deae82838f5173ea7cf89e85

PODFILE CHECKSUM: f4123c35c77493d6ddbcb86898737abdf5e0fac8
PODFILE CHECKSUM: 1e76f1bcc59e8c4c37db77ceb5ed375bef9b5d26

COCOAPODS: 1.5.3
16 changes: 14 additions & 2 deletions examples/video-caching/rn-cli.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
"use strict";

const path = require('path');
const blacklist = require('metro').createBlacklist;

const rootProjectDir = path.resolve(__dirname, '..', '..')

module.exports = {
// Resolve react-native-video from parent directory so we do not have to install react-native-video after each change applied
getBlacklistRE: function() {
return blacklist([/node_modules\/react-native-video\/examples\/.*/]);
return blacklist([/node_modules\/react-native-video\/.*/, new RegExp(`${rootProjectDir}/node_modules/react-native/.*`)])
},
getProjectRoots() {
return [
__dirname,
rootProjectDir
]
}
};
};
5 changes: 3 additions & 2 deletions ios/Video/RCTVideo.m
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ - (void)playerItemForSource:(NSDictionary *)source withCallback:(void(^)(AVPlaye
{
bool isNetwork = [RCTConvert BOOL:[source objectForKey:@"isNetwork"]];
bool isAsset = [RCTConvert BOOL:[source objectForKey:@"isAsset"]];
bool shouldCache = [RCTConvert BOOL:[source objectForKey:@"shouldCache"]];
NSString *uri = [source objectForKey:@"uri"];
NSString *type = [source objectForKey:@"type"];

Expand All @@ -483,9 +484,9 @@ - (void)playerItemForSource:(NSDictionary *)source withCallback:(void(^)(AVPlaye
[assetOptions setObject:cookies forKey:AVURLAssetHTTPCookiesKey];

#if __has_include(<react-native-video/RCTVideoCache.h>)
if (!_textTracks) {
if (shouldCache && (!_textTracks || !_textTracks.count)) {
/* The DVURLAsset created by cache doesn't have a tracksWithMediaType property, so trying
* to bring in the text track code will crash. I suspect this is because the asset hasn't fully loaded.
* to bring in the text track code will crash. I suspect this is because the asset hasn't fully loaded.
* Until this is fixed, we need to bypass caching when text tracks are specified.
*/
DebugLog(@"Caching is not supported for uri '%@' because text tracks are not compatible with the cache. Checkout https://github.com/react-native-community/react-native-video/blob/master/docs/caching.md", uri);
Expand Down