Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
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
7 changes: 7 additions & 0 deletions packages/video_player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.10.0+8

* iOS: Fix an issue where the player sends initialization message incorrectly.

* Fix a few other IDE warnings.


## 0.10.0+7

* Android: Fix issue where buffering status in percentage instead of milliseconds
Expand Down
51 changes: 28 additions & 23 deletions packages/video_player/ios/Classes/VideoPlayerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ @interface FLTVideoPlayer : NSObject <FlutterTexture, FlutterStreamHandler>
@property(nonatomic) CGAffineTransform preferredTransform;
@property(nonatomic, readonly) bool disposed;
@property(nonatomic, readonly) bool isPlaying;
@property(nonatomic, readonly) bool isLooping;
@property(nonatomic) bool isLooping;
@property(nonatomic, readonly) bool isInitialized;
- (instancetype)initWithURL:(NSURL*)url frameUpdater:(FLTFrameUpdater*)frameUpdater;
- (void)play;
Expand Down Expand Up @@ -97,6 +97,17 @@ - (void)addObservers:(AVPlayerItem*)item {
}];
}

static inline CGFloat radiansToDegrees(CGFloat radians) {
// Input range [-pi, pi] or [-180, 180]
CGFloat degrees = GLKMathRadiansToDegrees((float)radians);
if (degrees < 0) {
// Convert -90 to 270 and -180 to 180
return degrees + 360;
}
// Output degrees in between [0, 360[
return degrees;
};

- (AVMutableVideoComposition*)getVideoCompositionWithTransform:(CGAffineTransform)transform
withAsset:(AVAsset*)asset
withVideoTrack:(AVAssetTrack*)videoTrack {
Expand All @@ -113,8 +124,8 @@ - (AVMutableVideoComposition*)getVideoCompositionWithTransform:(CGAffineTransfor
videoComposition.instructions = @[ instruction ];

// If in portrait mode, switch the width and height of the video
float width = videoTrack.naturalSize.width;
float height = videoTrack.naturalSize.height;
CGFloat width = videoTrack.naturalSize.width;
CGFloat height = videoTrack.naturalSize.height;
NSInteger rotationDegrees =
(NSInteger)round(radiansToDegrees(atan2(_preferredTransform.b, _preferredTransform.a)));
if (rotationDegrees == 90 || rotationDegrees == 270) {
Expand Down Expand Up @@ -183,7 +194,7 @@ - (instancetype)initWithPlayerItem:(AVPlayerItem*)item frameUpdater:(FLTFrameUpd
if ([asset statusOfValueForKey:@"tracks" error:nil] == AVKeyValueStatusLoaded) {
NSArray* tracks = [asset tracksWithMediaType:AVMediaTypeVideo];
if ([tracks count] > 0) {
AVAssetTrack* videoTrack = [tracks objectAtIndex:0];
AVAssetTrack* videoTrack = tracks[0];
void (^trackCompletionHandler)(void) = ^{
if (self->_disposed) return;
if ([videoTrack statusOfValueForKey:@"preferredTransform"
Expand Down Expand Up @@ -236,7 +247,7 @@ - (void)observeValueForKeyPath:(NSString*)path
} else if (context == statusContext) {
AVPlayerItem* item = (AVPlayerItem*)object;
switch (item.status) {
case AVPlayerStatusFailed:
case AVPlayerItemStatusFailed:
if (_eventSink != nil) {
_eventSink([FlutterError
errorWithCode:@"VideoError"
Expand All @@ -248,7 +259,6 @@ - (void)observeValueForKeyPath:(NSString*)path
case AVPlayerItemStatusUnknown:
break;
case AVPlayerItemStatusReadyToPlay:
_isInitialized = true;
[item addOutput:_videoOutput];
[self sendInitialized];
[self updatePlayingState];
Expand Down Expand Up @@ -284,23 +294,18 @@ - (void)updatePlayingState {
_displayLink.paused = !_isPlaying;
}

static inline CGFloat radiansToDegrees(CGFloat radians) {
// Input range [-pi, pi] or [-180, 180]
CGFloat degrees = GLKMathRadiansToDegrees(radians);
if (degrees < 0) {
// Convert -90 to 270 and -180 to 180
return degrees + 360;
}
// Output degrees in between [0, 360[
return degrees;
};

- (void)sendInitialized {
if (_eventSink && _isInitialized) {
if (_eventSink && !_isInitialized) {
CGSize size = [self.player currentItem].presentationSize;
CGFloat width = size.width;
CGFloat height = size.height;

// The player has not yet initialized.
if (height == CGSizeZero.height && width == CGSizeZero.width) {
return;
}

_isInitialized = true;
_eventSink(@{
@"event" : @"initialized",
@"duration" : @([self duration]),
Expand Down Expand Up @@ -339,7 +344,7 @@ - (void)setIsLooping:(bool)isLooping {
}

- (void)setVolume:(double)volume {
_player.volume = (volume < 0.0) ? 0.0 : ((volume > 1.0) ? 1.0 : volume);
_player.volume = (float)((volume < 0.0) ? 0.0 : ((volume > 1.0) ? 1.0 : volume));
}

- (CVPixelBufferRef)copyPixelBuffer {
Expand Down Expand Up @@ -440,7 +445,7 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {

for (NSNumber* textureId in _players) {
[_registry unregisterTexture:[textureId unsignedIntegerValue]];
[[_players objectForKey:textureId] dispose];
[_players[textureId] dispose];
}
[_players removeAllObjects];
result(nil);
Expand Down Expand Up @@ -478,18 +483,18 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
[player dispose];
result(nil);
} else if ([@"setLooping" isEqualToString:call.method]) {
[player setIsLooping:[[argsMap objectForKey:@"looping"] boolValue]];
[player setIsLooping:[argsMap[@"looping"] boolValue]];
result(nil);
} else if ([@"setVolume" isEqualToString:call.method]) {
[player setVolume:[[argsMap objectForKey:@"volume"] doubleValue]];
[player setVolume:[argsMap[@"volume"] doubleValue]];
result(nil);
} else if ([@"play" isEqualToString:call.method]) {
[player play];
result(nil);
} else if ([@"position" isEqualToString:call.method]) {
result(@([player position]));
} else if ([@"seekTo" isEqualToString:call.method]) {
[player seekTo:[[argsMap objectForKey:@"location"] intValue]];
[player seekTo:[argsMap[@"location"] intValue]];
result(nil);
} else if ([@"pause" isEqualToString:call.method]) {
[player pause];
Expand Down
2 changes: 1 addition & 1 deletion packages/video_player/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: video_player
description: Flutter plugin for displaying inline video with other Flutter
widgets on Android and iOS.
author: Flutter Team <flutter-dev@googlegroups.com>
version: 0.10.0+7
version: 0.10.0+8
homepage: https://github.com/flutter/plugins/tree/master/packages/video_player

flutter:
Expand Down