From 91abfbde8b519e88d7eca71f9503d6a5311dc265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20=C3=87al=C4=B1k?= Date: Sun, 1 May 2016 17:41:30 +0300 Subject: [PATCH 1/2] [iOS] Added orientation to onLoad event. --- RCTVideo.m | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/RCTVideo.m b/RCTVideo.m index a613ded7..7d8cdb25 100644 --- a/RCTVideo.m +++ b/RCTVideo.m @@ -270,9 +270,19 @@ static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty"; NSObject *width = @"undefined"; NSObject *height = @"undefined"; + NSString *orientation = @"undefined"; + AVAssetTrack *vT = nil; + if ([_playerItem.asset tracksWithMediaType:AVMediaTypeVideo].count > 0) { - width = [NSNumber numberWithFloat:[_playerItem.asset tracksWithMediaType:AVMediaTypeVideo][0].naturalSize.width]; - height = [NSNumber numberWithFloat:[_playerItem.asset tracksWithMediaType:AVMediaTypeVideo][0].naturalSize.height]; + vT = [[_playerItem.asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]; + width = [NSNumber numberWithFloat:vT.naturalSize.width]; + height = [NSNumber numberWithFloat:vT.naturalSize.height]; + CGAffineTransform txf = [vT preferredTransform]; + + if ((vT.naturalSize.width == txf.tx && vT.naturalSize.height == txf.ty) | (txf.tx == 0 && txf.ty == 0)) + orientation = @"landscape"; + else + orientation = @"portrait"; } [_eventDispatcher sendInputEventWithName:@"onVideoLoad" @@ -286,7 +296,8 @@ static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty"; @"canStepForward": [NSNumber numberWithBool:_playerItem.canStepForward], @"naturalSize": @{ @"width": width, - @"height": height + @"height": height, + @"orientation": orientation }, @"target": self.reactTag}]; From 0c3cce542fd3351eb93d1e5ba2dd9d3c10c8d3e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20=C3=87al=C4=B1k?= Date: Sun, 1 May 2016 18:26:56 +0300 Subject: [PATCH 2/2] coding style fixes --- RCTVideo.m | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/RCTVideo.m b/RCTVideo.m index 7d8cdb25..ec886025 100644 --- a/RCTVideo.m +++ b/RCTVideo.m @@ -271,17 +271,19 @@ static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty"; NSObject *width = @"undefined"; NSObject *height = @"undefined"; NSString *orientation = @"undefined"; - AVAssetTrack *vT = nil; if ([_playerItem.asset tracksWithMediaType:AVMediaTypeVideo].count > 0) { - vT = [[_playerItem.asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]; - width = [NSNumber numberWithFloat:vT.naturalSize.width]; - height = [NSNumber numberWithFloat:vT.naturalSize.height]; - CGAffineTransform txf = [vT preferredTransform]; + AVAssetTrack *videoTrack = [[_playerItem.asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]; + width = [NSNumber numberWithFloat:videoTrack.naturalSize.width]; + height = [NSNumber numberWithFloat:videoTrack.naturalSize.height]; + CGAffineTransform preferredTransform = [videoTrack preferredTransform]; - if ((vT.naturalSize.width == txf.tx && vT.naturalSize.height == txf.ty) | (txf.tx == 0 && txf.ty == 0)) + if ((videoTrack.naturalSize.width == preferredTransform.tx + && videoTrack.naturalSize.height == preferredTransform.ty) + || (preferredTransform.tx == 0 && preferredTransform.ty == 0)) + { orientation = @"landscape"; - else + } else orientation = @"portrait"; }