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

AVPlayerLayer videoGravity support on iOS #10

Open
wants to merge 2 commits into
base: master
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
39 changes: 20 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,26 @@ export default class App extends Component {
- It may not work on Android simulator, in that case please run on device.
- For a more detailed example, please see [example/App.js](https://github.com/manse/react-native-brightcove-player/blob/master/example/App.js).

| Prop | Type | Description | Event Object |
| ---------------------- | -------- | ------------------------------------------------------------------------------- | ---------------------------- |
| accountId | string | Brightcove AccountId | |
| policyKey | string | Brightcove PolicyKey | |
| videoId | string | Brightcove VideoId. \*Either videoId or referenceId is required | |
| referenceId | string | Brightcove ReferenceId. \*Either videoId or referenceId is required | |
| autoPlay | boolean | Whether to play automatically when video loaded | |
| play | boolean | Control playback and pause | |
| fullscreen | boolean | Control full screen state | |
| disableDefaultControl | boolean | Disable default player control. Set true if you implement own video controller. | |
| onReady | Function | Indicates the video can be played back | |
| onPlay | Function | Indicates the video playback starts | |
| onPause | Function | Indicates the video is paused | |
| onEnd | Function | Indicates the video is played to the end | |
| onProgress | Function | Indicates the playback head of the video advances. | `{ currentTime: number }` |
| onChangeDuration | Function | Indicates the video length is changed | `{ duration: number }` |
| onUpdateBufferProgress | Function | Indicates the video loading buffer is updated | `{ bufferProgress: number }` |
| onEnterFullscreen | Function | Indicates the player enters full screen | |
| onExitFullscreen | Function | Indicates the player exit full screen | |
| Prop | Type | Default | iOS | Android | Description | Event Object |
| ---------------------- | -------- | - |- | - | ---------------------------------------------------------------------------- | ---------------------------- |
| accountId | string | | ✅ | ✅ | Brightcove AccountId | |
| policyKey | string | | ✅ | ✅ | Brightcove PolicyKey | |
| videoId | string | | ✅ | ✅ | Brightcove VideoId. \*Either videoId or referenceId is required | |
| referenceId | string | | ✅ | ✅ | Brightcove ReferenceId. \*Either videoId or referenceId is required | |
| autoPlay | boolean | | ✅ | ✅ | Whether to play automatically when video loaded | |
| play | boolean | | ✅ | ✅ | Control playback and pause | |
| fullscreen | boolean | | ✅ | ✅ | Control full screen state | |
| disableDefaultControl | boolean | | ✅ | ✅ | Disable default player control. Set true if you implement own video controller. | |
| onReady | Function | | ✅ | ✅ | Indicates the video can be played back | |
| onPlay | Function | | ✅ | ✅ | Indicates the video playback starts | |
| onPause | Function | | ✅ | ✅ | Indicates the video is paused | |
| onEnd | Function | | ✅ | ✅ | Indicates the video is played to the end | |
| onProgress | Function | | ✅ | ✅ | Indicates the playback head of the video advances. | `{ currentTime: number }` |
| onChangeDuration | Function | | ✅ | ✅ | Indicates the video length is changed | `{ duration: number }` |
| onUpdateBufferProgress | Function | | ✅ | ✅ | Indicates the video loading buffer is updated | `{ bufferProgress: number }` |
| onEnterFullscreen | Function | | ✅ | ✅ | Indicates the player enters full screen | |
| onExitFullscreen | Function | | ✅ | ✅ | Indicates the player exit full screen | |
| resizeAspectFill | boolean | false | ✅ | ❌ | Specifies that the player should preserve the video’s aspect ratio and fill the layer’s bounds. See: [AVFoundation > AVPlayerLayer > videoGravity ](https://developer.apple.com/documentation/avfoundation/avplayerlayer/1388915-videogravity?language=objc) | |

| Method | Description |
| ------------------------------------- | --------------------------------- |
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type Props = {
onEnd?: () => void;
onProgress?: ({ currentTime: number }) => void;
style?: ViewStyle;
resizeAspectFill?: boolean;
};

export class BrightcovePlayer extends React.Component<Props, {}> {
Expand Down
12 changes: 12 additions & 0 deletions ios/BrightcovePlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ @interface BrightcovePlayer () <BCOVPlaybackControllerDelegate, BCOVPUIPlayerVie

@implementation BrightcovePlayer

BOOL _resizeAspectFill;

- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
_resizeAspectFill = false;
[self setup];
}
return self;
Expand Down Expand Up @@ -56,6 +59,10 @@ - (void)loadMovie {
return [BCOVPlayerSDKManager.sharedManager createPlaybackControllerWithSessionProvider:provider viewStrategy:nil];
}

- (void)setResizeAspectFill:(BOOL)resizeAspectFill {
_resizeAspectFill = resizeAspectFill;
}

- (void)setReferenceId:(NSString *)referenceId {
_referenceId = referenceId;
_videoId = NULL;
Expand Down Expand Up @@ -113,6 +120,11 @@ - (void)seekTo:(NSNumber *)time {
}

- (void)playbackController:(id<BCOVPlaybackController>)controller playbackSession:(id<BCOVPlaybackSession>)session didReceiveLifecycleEvent:(BCOVPlaybackSessionLifecycleEvent *)lifecycleEvent {

if(_resizeAspectFill) {
session.playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
}

if (lifecycleEvent.eventType == kBCOVPlaybackSessionLifecycleEventReady) {
if (self.onReady) {
self.onReady(@{});
Expand Down
1 change: 1 addition & 0 deletions ios/BrightcovePlayerManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ - (dispatch_queue_t)methodQueue {
RCT_EXPORT_VIEW_PROPERTY(onUpdateBufferProgress, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onEnterFullscreen, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onExitFullscreen, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(resizeAspectFill, BOOL);

RCT_EXPORT_METHOD(seekTo:(nonnull NSNumber *)reactTag seconds:(nonnull NSNumber *)seconds) {
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
Expand Down
4 changes: 2 additions & 2 deletions ios/react-native-brightcove-player.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.2;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -222,7 +222,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.2;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
Expand Down
3 changes: 2 additions & 1 deletion src/BrightcovePlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ BrightcovePlayer.propTypes = {
onChangeDuration: PropTypes.func,
onUpdateBufferProgress: PropTypes.func,
onEnterFullscreen: PropTypes.func,
onExitFullscreen: PropTypes.func
onExitFullscreen: PropTypes.func,
resizeAspectFill: PropTypes.bool
};

BrightcovePlayer.defaultProps = {};
Expand Down