Skip to content
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
14 changes: 6 additions & 8 deletions react-native-video.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,27 @@ Pod::Spec.new do |s|

s.subspec "Video" do |ss|
ss.source_files = "ios/Video/**/*.{h,m,swift,mm}"
swift_flags = ['$(inherited)']

if fabric_enabled
ss.dependency "react-native-video/Fabric"
end

if defined?($RNVideoUseGoogleIMA)
if defined?($RNVideoUseGoogleIMA) && $RNVideoUseGoogleIMA
Pod::UI.puts "RNVideo: enable IMA SDK"

ss.ios.dependency 'GoogleAds-IMA-iOS-SDK', '~> 3.22.1'
ss.tvos.dependency 'GoogleAds-IMA-tvOS-SDK', '~> 4.2'
ss.pod_target_xcconfig = {
'OTHER_SWIFT_FLAGS' => '$(inherited) -D USE_GOOGLE_IMA'
}
swift_flags << '-D USE_GOOGLE_IMA'
end
if defined?($RNVideoUseVideoCaching)
if defined?($RNVideoUseVideoCaching) && $RNVideoUseVideoCaching
Pod::UI.puts "RNVideo: enable Video caching"
ss.dependency "SPTPersistentCache", "~> 1.1.0"
ss.dependency "DVAssetLoaderDelegate", "~> 0.3.1"
ss.source_files = "ios/*/**/*.{h,m,swift,mm}"
ss.pod_target_xcconfig = {
'OTHER_SWIFT_FLAGS' => '$(inherited) -D USE_VIDEO_CACHING'
}
swift_flags << '-D USE_VIDEO_CACHING'
end
ss.pod_target_xcconfig = { 'OTHER_SWIFT_FLAGS' => swift_flags.join(' ') }
end

# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
Expand Down
18 changes: 10 additions & 8 deletions src/expo-plugins/withAndroidPictureInPicture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@ export const withAndroidPictureInPicture: ConfigPlugin<boolean> = (
enableAndroidPictureInPicture,
) => {
return withAndroidManifest(config, (_config) => {
if (!enableAndroidPictureInPicture) {
return _config;
}

const mainActivity = AndroidConfig.Manifest.getMainActivity(
_config.modResults,
);

if (!mainActivity) {
console.warn(
'AndroidManifest.xml is missing an <activity android:name=".MainActivity" /> element - skipping adding Picture-In-Picture related config.',
);
if (enableAndroidPictureInPicture) {
console.warn(
'AndroidManifest.xml is missing an <activity android:name=".MainActivity" /> element - skipping adding Picture-In-Picture related config.',
);
}
return _config;
}

mainActivity.$['android:supportsPictureInPicture'] = 'true';
if (enableAndroidPictureInPicture) {
mainActivity.$['android:supportsPictureInPicture'] = 'true';
} else {
delete mainActivity.$['android:supportsPictureInPicture'];
}

return _config;
});
Expand Down
9 changes: 6 additions & 3 deletions src/expo-plugins/withBackgroundAudio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ export const withBackgroundAudio: ConfigPlugin<boolean> = (
config.modResults.UIBackgroundModes = [...modes, 'audio'];
}
} else {
config.modResults.UIBackgroundModes = modes.filter(
(mode: string) => mode !== 'audio',
);
const remainingModes = modes.filter((mode: string) => mode !== 'audio');
if (remainingModes.length > 0) {
config.modResults.UIBackgroundModes = remainingModes;
} else {
delete config.modResults.UIBackgroundModes;
}
}

return config;
Expand Down
42 changes: 18 additions & 24 deletions src/expo-plugins/withNotificationControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,32 @@ export const withNotificationControls: ConfigPlugin<boolean> = (
return withAndroidManifest(c, (config) => {
const manifest = config.modResults.manifest;

if (!enableNotificationControls) {
return config;
}

if (!manifest.application) {
console.warn(
'AndroidManifest.xml is missing an <application> element - skipping adding notification controls related config.',
);
if (enableNotificationControls) {
console.warn(
'AndroidManifest.xml is missing an <application> element - skipping adding notification controls related config.',
);
}
return config;
}

// Add the service to the AndroidManifest.xml
manifest.application.map((application) => {
if (!application.service) {
application.service = [];
}

// We check if the VideoPlaybackService is already defined in the AndroidManifest.xml
// to prevent adding duplicate service entries. If the service exists, we will remove
// it before adding the updated configuration to ensure there are no conflicts or redundant
// service declarations in the manifest.
const existingServiceIndex = application.service.findIndex(
manifest.application.forEach((application) => {
const services = (application.service ?? []).filter(
(service) =>
service?.$?.['android:name'] ===
service?.$?.['android:name'] !==
'com.brentvatne.exoplayer.VideoPlaybackService',
);
if (existingServiceIndex !== -1) {
application.service.splice(existingServiceIndex, 1);

if (!enableNotificationControls) {
if (services.length > 0) {
application.service = services;
} else {
delete application.service;
}
return;
}

application.service.push({
services.push({
$: {
'android:name': 'com.brentvatne.exoplayer.VideoPlaybackService',
'android:exported': 'false',
Expand All @@ -56,8 +51,7 @@ export const withNotificationControls: ConfigPlugin<boolean> = (
},
],
});

return application;
application.service = services;
});

return config;
Expand Down
39 changes: 17 additions & 22 deletions src/expo-plugins/withRNVideo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,37 @@ const pkg = require('../../package.json');
const withRNVideo: ConfigPlugin<ConfigProps> = (config, props = {}) => {
const androidPermissions = [];

config = withNotificationControls(
config,
props.enableNotificationControls ?? false,
);
if (props.enableNotificationControls) {
config = withNotificationControls(config, props.enableNotificationControls);
androidPermissions.push('android.permission.FOREGROUND_SERVICE');
androidPermissions.push(
'android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK',
);
}

if (props.enableAndroidPictureInPicture) {
config = withAndroidPictureInPicture(
config,
props.enableAndroidPictureInPicture,
);
}
config = withAndroidPictureInPicture(
config,
props.enableAndroidPictureInPicture ?? false,
);

if (props.androidExtensions != null) {
config = withAndroidExtensions(config, props.androidExtensions);
}

if (props.enableADSExtension) {
config = withAds(config, {
enableADSExtension: props.enableADSExtension,
testApp: props.reactNativeTestApp,
});
}
config = withAds(config, {
enableADSExtension: props.enableADSExtension ?? false,
testApp: props.reactNativeTestApp,
});

if (props.enableCacheExtension) {
config = withCaching(config, {
enableCachingExtension: props.enableCacheExtension,
testApp: props.reactNativeTestApp,
});
}
config = withCaching(config, {
enableCachingExtension: props.enableCacheExtension ?? false,
testApp: props.reactNativeTestApp,
});

if (props.enableBackgroundAudio) {
config = withBackgroundAudio(config, props.enableBackgroundAudio);
}
config = withBackgroundAudio(config, props.enableBackgroundAudio ?? false);

config = withPermissions(config, androidPermissions);

Expand Down
6 changes: 5 additions & 1 deletion src/expo-plugins/writeToPodfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ export const writeToPodfile = (
) => {
const podfilePath = path.join(projectRoot, 'ios', 'Podfile');
const podfileContent = fs.readFileSync(podfilePath, 'utf8');
const generatedTag = `rn-video-set-${key.toLowerCase()}`;

if (podfileContent.includes(`$${key} =`)) {
if (
podfileContent.includes(`$${key} =`) &&
!podfileContent.includes(`@generated begin ${generatedTag} `)
) {
console.warn(
`RNV - Podfile already contains a definition for "$${key}". Skipping...`,
);
Expand Down
Loading