Skip to content

Commit 3a39dbb

Browse files
n1ru4lAnteWall
authored andcommitted
fix: omit packager assets from caching (TheWidlarzGroup#1438)
1 parent 40d65c5 commit 3a39dbb

File tree

7 files changed

+87
-30
lines changed

7 files changed

+87
-30
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Changelog
22

3+
### next
4+
5+
* Fix loading package resolved videos when using video-caching [#1438](https://github.com/react-native-community/react-native-video/pull/1438)
6+
37
### Version 4.3.0
48
* Fix iOS video not displaying after switching source [#1395](https://github.com/react-native-community/react-native-video/pull/1395)
59
* Add the filterEnabled flag, fixes iOS video start time regression [#1384](https://github.com/react-native-community/react-native-video/pull/1384)

Video.js

+2
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ export default class Video extends Component {
229229
render() {
230230
const resizeMode = this.props.resizeMode;
231231
const source = resolveAssetSource(this.props.source) || {};
232+
const shouldCache = !Boolean(source.__packager_asset)
232233

233234
let uri = source.uri || '';
234235
if (uri && uri.match(/^\//)) {
@@ -257,6 +258,7 @@ export default class Video extends Component {
257258
uri,
258259
isNetwork,
259260
isAsset,
261+
shouldCache,
260262
type: source.type || '',
261263
mainVer: source.mainVer || 0,
262264
patchVer: source.patchVer || 0,

examples/video-caching/App.ios.js

+58-20
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,70 @@
55
*/
66

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

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

1313
type Props = {};
14-
export default class App extends Component<Props> {
14+
15+
type State = {
16+
showLocal: boolean
17+
};
18+
19+
function Button({ text, onPress }: { text: string, onPress: () => void }) {
20+
return (
21+
<TouchableOpacity
22+
onPress={onPress}
23+
style={styles.button}
24+
>
25+
<Text style={{color: 'white'}}>{text}</Text>
26+
</TouchableOpacity>
27+
)
28+
}
29+
30+
export default class App extends Component<Props, State> {
31+
state = {
32+
showLocal: false
33+
}
1534
render() {
1635
return (
1736
<View style={styles.container}>
1837
<Video
19-
source={{
20-
uri:
21-
"https://rawgit.com/mediaelement/mediaelement-files/master/big_buck_bunny.mp4"
22-
}}
38+
source={
39+
this.state.showLocal ?
40+
require('../basic/broadchurch.mp4') :
41+
{
42+
uri: "https://rawgit.com/mediaelement/mediaelement-files/master/big_buck_bunny.mp4"
43+
}
44+
}
2345
ref={player => {
2446
this.player = player;
2547
}}
2648
onEnd={() => {
2749
this.player.seek(0);
2850
}}
51+
onError={(err) => {
52+
Alert.alert(JSON.stringify(err))
53+
}}
2954
style={{ flex: 1, height, width }}
3055
/>
31-
<TouchableOpacity
32-
onPress={async () => {
33-
let response = await this.player.save();
34-
let uri = response.uri;
35-
console.log("Download URI", uri);
36-
}}
37-
style={styles.button}
38-
>
39-
<Text style={{color: 'white'}}>Save</Text>
40-
</TouchableOpacity>
56+
<View style={styles.absoluteOverlay}>
57+
<Button
58+
onPress={async () => {
59+
let response = await this.player.save();
60+
let uri = response.uri;
61+
console.warn("Download URI", uri);
62+
}}
63+
text="Save"
64+
/>
65+
<Button
66+
onPress={() => {
67+
this.setState(state => ({ showLocal: !state.showLocal }))
68+
}}
69+
text={this.state.showLocal ? "Show Remote" : "Show Local"}
70+
/>
71+
</View>
4172
</View>
4273
);
4374
}
@@ -50,13 +81,20 @@ const styles = StyleSheet.create({
5081
alignItems: "center",
5182
backgroundColor: "#F5FCFF"
5283
},
53-
button: {
84+
absoluteOverlay: {
85+
flexDirection: 'row',
5486
position: 'absolute',
55-
top: 50,
56-
right: 16,
87+
top: 0,
88+
width: '100%',
89+
marginTop: 50,
90+
},
91+
button: {
5792
padding: 10,
5893
backgroundColor: '#9B2FAE',
59-
borderRadius: 8
94+
borderRadius: 8,
95+
flex: 1,
96+
alignItems: 'center',
97+
marginHorizontal: 5,
6098
},
6199
welcome: {
62100
fontSize: 20,

examples/video-caching/ios/Podfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ target 'VideoCaching' do
2828
'DevSupport'
2929
]
3030

31-
pod 'react-native-video/VideoCaching', :path => '../node_modules/react-native-video/react-native-video.podspec'
31+
pod 'react-native-video/VideoCaching', :path => '../../../react-native-video.podspec'
3232
end

examples/video-caching/ios/Podfile.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ PODS:
99
- glog (0.3.4)
1010
- React (0.56.0):
1111
- React/Core (= 0.56.0)
12-
- react-native-video/Video (3.2.2):
12+
- react-native-video/Video (4.3.1):
1313
- React
14-
- react-native-video/VideoCaching (3.2.2):
14+
- react-native-video/VideoCaching (4.3.1):
1515
- DVAssetLoaderDelegate (~> 0.3.1)
1616
- React
1717
- react-native-video/Video
@@ -73,7 +73,7 @@ DEPENDENCIES:
7373
- DoubleConversion (from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`)
7474
- Folly (from `../node_modules/react-native/third-party-podspecs/Folly.podspec`)
7575
- glog (from `../node_modules/react-native/third-party-podspecs/GLog.podspec`)
76-
- react-native-video/VideoCaching (from `../node_modules/react-native-video/react-native-video.podspec`)
76+
- react-native-video/VideoCaching (from `../../../react-native-video.podspec`)
7777
- React/Core (from `../node_modules/react-native`)
7878
- React/CxxBridge (from `../node_modules/react-native`)
7979
- React/DevSupport (from `../node_modules/react-native`)
@@ -108,7 +108,7 @@ EXTERNAL SOURCES:
108108
React:
109109
:path: "../node_modules/react-native"
110110
react-native-video:
111-
:path: "../node_modules/react-native-video/react-native-video.podspec"
111+
:path: "../../../react-native-video.podspec"
112112
yoga:
113113
:path: "../node_modules/react-native/ReactCommon/yoga/yoga.podspec"
114114

@@ -123,6 +123,6 @@ SPEC CHECKSUMS:
123123
SPTPersistentCache: df36ea46762d7cf026502bbb86a8b79d0080dff4
124124
yoga: b1ce48b6cf950b98deae82838f5173ea7cf89e85
125125

126-
PODFILE CHECKSUM: f4123c35c77493d6ddbcb86898737abdf5e0fac8
126+
PODFILE CHECKSUM: 1e76f1bcc59e8c4c37db77ceb5ed375bef9b5d26
127127

128128
COCOAPODS: 1.5.3
+14-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1+
"use strict";
2+
3+
const path = require('path');
14
const blacklist = require('metro').createBlacklist;
25

6+
const rootProjectDir = path.resolve(__dirname, '..', '..')
7+
38
module.exports = {
9+
// Resolve react-native-video from parent directory so we do not have to install react-native-video after each change applied
410
getBlacklistRE: function() {
5-
return blacklist([/node_modules\/react-native-video\/examples\/.*/]);
11+
return blacklist([/node_modules\/react-native-video\/.*/, new RegExp(`${rootProjectDir}/node_modules/react-native/.*`)])
12+
},
13+
getProjectRoots() {
14+
return [
15+
__dirname,
16+
rootProjectDir
17+
]
618
}
7-
};
19+
};

ios/Video/RCTVideo.m

+3-2
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ - (void)playerItemForSource:(NSDictionary *)source withCallback:(void(^)(AVPlaye
468468
{
469469
bool isNetwork = [RCTConvert BOOL:[source objectForKey:@"isNetwork"]];
470470
bool isAsset = [RCTConvert BOOL:[source objectForKey:@"isAsset"]];
471+
bool shouldCache = [RCTConvert BOOL:[source objectForKey:@"shouldCache"]];
471472
NSString *uri = [source objectForKey:@"uri"];
472473
NSString *type = [source objectForKey:@"type"];
473474
if([uri isEqualToString:@""] && [type isEqualToString:@""]) {
@@ -492,9 +493,9 @@ - (void)playerItemForSource:(NSDictionary *)source withCallback:(void(^)(AVPlaye
492493
[assetOptions setObject:cookies forKey:AVURLAssetHTTPCookiesKey];
493494

494495
#if __has_include(<react-native-video/RCTVideoCache.h>)
495-
if (!_textTracks) {
496+
if (shouldCache && (!_textTracks || !_textTracks.count)) {
496497
/* The DVURLAsset created by cache doesn't have a tracksWithMediaType property, so trying
497-
* to bring in the text track code will crash. I suspect this is because the asset hasn't fully loaded.
498+
* to bring in the text track code will crash. I suspect this is because the asset hasn't fully loaded.
498499
* Until this is fixed, we need to bypass caching when text tracks are specified.
499500
*/
500501
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);

0 commit comments

Comments
 (0)