Skip to content

Commit

Permalink
[Android] Fix require(...) file resource on production (#429)
Browse files Browse the repository at this point in the history
* Fix require(...) file resource on Android production

* Update example (use require for ./broadchurch.mp4)

* Fix MainApplication.java of example

* Add default source type
  • Loading branch information
jhen0409 authored and Matt Apperson committed Jan 31, 2017
1 parent 201335f commit d450afc
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,17 @@ public void setSrc(final ReactExoplayerView videoView, @Nullable ReadableMap src
}
} else {
int identifier = context.getResources().getIdentifier(
uriString,
"drawable",
context.getPackageName()
);
if (identifier == 0) {
identifier = context.getResources().getIdentifier(
uriString,
"raw",
context.getPackageName()
);
);
}
if (identifier > 0) {
Uri srcUri = RawResourceDataSource.buildRawResourceUri(identifier);
if (srcUri != null) {
Expand Down
12 changes: 10 additions & 2 deletions android/src/main/java/com/brentvatne/react/ReactVideoView.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,19 @@ public void setSrc(final String uriString, final String type, final boolean isNe
}
}
if(fd==null) {
setRawData(mThemedReactContext.getResources().getIdentifier(
int identifier = mThemedReactContext.getResources().getIdentifier(
uriString,
"drawable",
mThemedReactContext.getPackageName()
);
if (identifier == 0) {
identifier = mThemedReactContext.getResources().getIdentifier(
uriString,
"raw",
mThemedReactContext.getPackageName()
));
);
}
setRawData(identifier);
}
else {
setDataSource(fd.getFileDescriptor(), fd.getStartOffset(),fd.getLength());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,17 @@

public class MainApplication extends Application implements ReactApplication {

private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}

@Override
protected List<ReactPackage> getPackages() {
return Arrays.asList(
new MainReactPackage(),
new ReactVideoPackage()
);
}
};

private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}

@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new ReactVideoPackage()
return Arrays.asList(
new MainReactPackage(),
new ReactVideoPackage()
);
}
};
Expand Down
Binary file removed example/android/app/src/main/res/raw/broadchurch.mp4
Binary file not shown.
3 changes: 1 addition & 2 deletions example/index.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ class VideoPlayer extends Component {
<Video
ref={(ref: Video) => { this.video = ref }}
/* For ExoPlayer */
/* source={require('./broadchurch.mp4')} */
/* source={{ uri: 'http://www.youtube.com/api/manifest/dash/id/bf5bb2419360daf1/source/youtube?as=fmp4_audio_clear,fmp4_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=51AF5F39AB0CEC3E5497CD9C900EBFEAECCCB5C7.8506521BFC350652163895D4C26DEE124209AA9E&key=ik0', type: 'mpd' }} */
source={{ uri: 'broadchurch', type: 'mp4' }}
source={require('./broadchurch.mp4')}
style={styles.fullScreen}
rate={this.state.rate}
paused={this.state.paused}
Expand Down
4 changes: 2 additions & 2 deletions example/index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class VideoPlayer extends Component {
<View style={styles.container}>
<TouchableOpacity style={styles.fullScreen} onPress={() => {this.setState({paused: !this.state.paused})}}>
<Video
source={{uri: "broadchurch"}}
source={require('./broadchurch.mp4')}
style={styles.fullScreen}
rate={this.state.rate}
paused={this.state.paused}
Expand Down Expand Up @@ -174,7 +174,7 @@ class VideoPlayer extends Component {
<View style={styles.container}>
<View style={styles.fullScreen}>
<Video
source={{uri: "broadchurch"}}
source={require('./broadchurch.mp4')}
style={videoStyle}
rate={this.state.rate}
paused={this.state.paused}
Expand Down
14 changes: 2 additions & 12 deletions example/ios/VideoPlayer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
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 */; };
8C2A0F861E25610700E31596 /* broadchurch.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = 8C2A0F851E25610200E31596 /* broadchurch.mp4 */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -244,7 +243,6 @@
78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; };
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; };
8C2A0F651E25608300E31596 /* RCTVideo.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTVideo.xcodeproj; path = "../node_modules/react-native-video/ios/RCTVideo.xcodeproj"; sourceTree = "<group>"; };
8C2A0F851E25610200E31596 /* broadchurch.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; name = broadchurch.mp4; path = ../broadchurch.mp4; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -433,7 +431,6 @@
83CBB9F61A601CBA00E9B192 = {
isa = PBXGroup;
children = (
8C2A0F851E25610200E31596 /* broadchurch.mp4 */,
13B07FAE1A68108700A75B9A /* VideoPlayer */,
832341AE1AAA6A7D00B99B32 /* Libraries */,
00E356EF1AD99517003FC87E /* VideoPlayerTests */,
Expand Down Expand Up @@ -782,7 +779,6 @@
files = (
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */,
8C2A0F861E25610700E31596 /* broadchurch.mp4 in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -802,7 +798,6 @@
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "export NODE_BINARY=node\n../node_modules/react-native/packager/react-native-xcode.sh";
showEnvVarsInLog = 1;
};
/* End PBXShellScriptBuildPhase section */

Expand Down Expand Up @@ -882,10 +877,8 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = NO;

INFOPLIST_FILE = VideoPlayer/Info.plist;

LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
Expand All @@ -901,10 +894,8 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = 1;

INFOPLIST_FILE = VideoPlayer/Info.plist;

LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
Expand Down Expand Up @@ -984,7 +975,6 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;

IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
Expand Down

0 comments on commit d450afc

Please sign in to comment.