2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
5
- #import " FLTVideoPlayerPlugin .h"
6
- #import " FLTVideoPlayerPlugin_Test .h"
5
+ #import " FVPVideoPlayerPlugin .h"
6
+ #import " FVPVideoPlayerPlugin_Test .h"
7
7
8
8
#import < AVFoundation/AVFoundation.h>
9
9
#import < GLKit/GLKit.h>
15
15
#error Code Requires ARC.
16
16
#endif
17
17
18
- @interface FLTFrameUpdater : NSObject
18
+ @interface FVPFrameUpdater : NSObject
19
19
@property (nonatomic ) int64_t textureId;
20
20
@property (nonatomic , weak , readonly ) NSObject <FlutterTextureRegistry> *registry;
21
21
- (void )onDisplayLink : (CADisplayLink *)link ;
22
22
@end
23
23
24
- @implementation FLTFrameUpdater
25
- - (FLTFrameUpdater *)initWithRegistry : (NSObject <FlutterTextureRegistry> *)registry {
24
+ @implementation FVPFrameUpdater
25
+ - (FVPFrameUpdater *)initWithRegistry : (NSObject <FlutterTextureRegistry> *)registry {
26
26
NSAssert (self, @" super init cannot be nil" );
27
27
if (self == nil ) return nil ;
28
28
_registry = registry;
@@ -44,7 +44,7 @@ - (AVPlayer *)playerWithPlayerItem:(AVPlayerItem *)playerItem {
44
44
45
45
@end
46
46
47
- @interface FLTVideoPlayer : NSObject <FlutterTexture, FlutterStreamHandler>
47
+ @interface FVPVideoPlayer : NSObject <FlutterTexture, FlutterStreamHandler>
48
48
@property (readonly , nonatomic ) AVPlayer *player;
49
49
@property (readonly , nonatomic ) AVPlayerItemVideoOutput *videoOutput;
50
50
// This is to fix 2 bugs: 1. blank video for encrypted video streams on iOS 16
@@ -62,7 +62,7 @@ @interface FLTVideoPlayer : NSObject <FlutterTexture, FlutterStreamHandler>
62
62
@property (nonatomic ) BOOL isLooping;
63
63
@property (nonatomic , readonly ) BOOL isInitialized;
64
64
- (instancetype )initWithURL : (NSURL *)url
65
- frameUpdater : (FLTFrameUpdater *)frameUpdater
65
+ frameUpdater : (FVPFrameUpdater *)frameUpdater
66
66
httpHeaders : (nonnull NSDictionary <NSString *, NSString *> *)headers
67
67
playerFactory : (id <FVPPlayerFactory>)playerFactory ;
68
68
@end
@@ -74,9 +74,9 @@ - (instancetype)initWithURL:(NSURL *)url
74
74
static void *playbackLikelyToKeepUpContext = &playbackLikelyToKeepUpContext;
75
75
static void *rateContext = &rateContext;
76
76
77
- @implementation FLTVideoPlayer
77
+ @implementation FVPVideoPlayer
78
78
- (instancetype )initWithAsset : (NSString *)asset
79
- frameUpdater : (FLTFrameUpdater *)frameUpdater
79
+ frameUpdater : (FVPFrameUpdater *)frameUpdater
80
80
playerFactory : (id <FVPPlayerFactory>)playerFactory {
81
81
NSString *path = [[NSBundle mainBundle ] pathForResource: asset ofType: nil ];
82
82
return [self initWithURL: [NSURL fileURLWithPath: path]
@@ -134,7 +134,7 @@ - (void)itemDidPlayToEndTime:(NSNotification *)notification {
134
134
135
135
const int64_t TIME_UNSET = -9223372036854775807 ;
136
136
137
- NS_INLINE int64_t FLTCMTimeToMillis (CMTime time) {
137
+ NS_INLINE int64_t FVPCMTimeToMillis (CMTime time) {
138
138
// When CMTIME_IS_INDEFINITE return a value that matches TIME_UNSET from ExoPlayer2 on Android.
139
139
// Fixes https://github.com/flutter/flutter/issues/48670
140
140
if (CMTIME_IS_INDEFINITE (time )) return TIME_UNSET;
@@ -195,7 +195,7 @@ - (AVMutableVideoComposition *)getVideoCompositionWithTransform:(CGAffineTransfo
195
195
return videoComposition;
196
196
}
197
197
198
- - (void )createVideoOutputAndDisplayLink : (FLTFrameUpdater *)frameUpdater {
198
+ - (void )createVideoOutputAndDisplayLink : (FVPFrameUpdater *)frameUpdater {
199
199
NSDictionary *pixBuffAttributes = @{
200
200
(id )kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_32BGRA ),
201
201
(id )kCVPixelBufferIOSurfacePropertiesKey : @{}
@@ -209,7 +209,7 @@ - (void)createVideoOutputAndDisplayLink:(FLTFrameUpdater *)frameUpdater {
209
209
}
210
210
211
211
- (instancetype )initWithURL : (NSURL *)url
212
- frameUpdater : (FLTFrameUpdater *)frameUpdater
212
+ frameUpdater : (FVPFrameUpdater *)frameUpdater
213
213
httpHeaders : (nonnull NSDictionary <NSString *, NSString *> *)headers
214
214
playerFactory : (id <FVPPlayerFactory>)playerFactory {
215
215
NSDictionary <NSString *, id > *options = nil ;
@@ -222,7 +222,7 @@ - (instancetype)initWithURL:(NSURL *)url
222
222
}
223
223
224
224
- (instancetype )initWithPlayerItem : (AVPlayerItem *)item
225
- frameUpdater : (FLTFrameUpdater *)frameUpdater
225
+ frameUpdater : (FVPFrameUpdater *)frameUpdater
226
226
playerFactory : (id <FVPPlayerFactory>)playerFactory {
227
227
self = [super init ];
228
228
NSAssert (self, @" super init cannot be nil" );
@@ -238,7 +238,7 @@ - (instancetype)initWithPlayerItem:(AVPlayerItem *)item
238
238
if ([videoTrack statusOfValueForKey: @" preferredTransform"
239
239
error: nil ] == AVKeyValueStatusLoaded) {
240
240
// Rotate the video by using a videoComposition and the preferredTransform
241
- self->_preferredTransform = FLTGetStandardizedTransformForTrack (videoTrack);
241
+ self->_preferredTransform = FVPGetStandardizedTransformForTrack (videoTrack);
242
242
// Note:
243
243
// https://developer.apple.com/documentation/avfoundation/avplayeritem/1388818-videocomposition
244
244
// Video composition can only be used with file-based media and is not supported for
@@ -285,8 +285,8 @@ - (void)observeValueForKeyPath:(NSString *)path
285
285
NSMutableArray <NSArray <NSNumber *> *> *values = [[NSMutableArray alloc ] init ];
286
286
for (NSValue *rangeValue in [object loadedTimeRanges ]) {
287
287
CMTimeRange range = [rangeValue CMTimeRangeValue ];
288
- int64_t start = FLTCMTimeToMillis (range.start );
289
- [values addObject: @[ @(start), @(start + FLTCMTimeToMillis (range.duration)) ]];
288
+ int64_t start = FVPCMTimeToMillis (range.start );
289
+ [values addObject: @[ @(start), @(start + FVPCMTimeToMillis (range.duration)) ]];
290
290
}
291
291
_eventSink (@{@" event" : @" bufferingUpdate" , @" values" : values});
292
292
}
@@ -414,14 +414,14 @@ - (void)pause {
414
414
}
415
415
416
416
- (int64_t )position {
417
- return FLTCMTimeToMillis ([_player currentTime ]);
417
+ return FVPCMTimeToMillis ([_player currentTime ]);
418
418
}
419
419
420
420
- (int64_t )duration {
421
421
// Note: https://openradar.appspot.com/radar?id=4968600712511488
422
422
// `[AVPlayerItem duration]` can be `kCMTimeIndefinite`,
423
423
// use `[[AVPlayerItem asset] duration]` instead.
424
- return FLTCMTimeToMillis ([[[_player currentItem ] asset ] duration ]);
424
+ return FVPCMTimeToMillis ([[[_player currentItem ] asset ] duration ]);
425
425
}
426
426
427
427
- (void )seekTo : (int )location completionHandler : (void (^)(BOOL ))completionHandler {
@@ -507,8 +507,8 @@ - (FlutterError *_Nullable)onListenWithArguments:(id _Nullable)arguments
507
507
- (void )disposeSansEventChannel {
508
508
// This check prevents the crash caused by removing the KVO observers twice.
509
509
// When performing a Hot Restart, the leftover players are disposed once directly
510
- // by [FLTVideoPlayerPlugin initialize:] method and then disposed again by
511
- // [FLTVideoPlayer onTextureUnregistered:] call leading to possible over-release.
510
+ // by [FVPVideoPlayerPlugin initialize:] method and then disposed again by
511
+ // [FVPVideoPlayer onTextureUnregistered:] call leading to possible over-release.
512
512
if (_disposed) {
513
513
return ;
514
514
}
@@ -535,20 +535,20 @@ - (void)dispose {
535
535
536
536
@end
537
537
538
- @interface FLTVideoPlayerPlugin () <FLTAVFoundationVideoPlayerApi >
538
+ @interface FVPVideoPlayerPlugin () <FVPAVFoundationVideoPlayerApi >
539
539
@property (readonly , weak , nonatomic ) NSObject <FlutterTextureRegistry> *registry;
540
540
@property (readonly , weak , nonatomic ) NSObject <FlutterBinaryMessenger> *messenger;
541
541
@property (readonly , strong , nonatomic )
542
- NSMutableDictionary <NSNumber *, FLTVideoPlayer *> *playersByTextureId;
542
+ NSMutableDictionary <NSNumber *, FVPVideoPlayer *> *playersByTextureId;
543
543
@property (readonly , strong , nonatomic ) NSObject <FlutterPluginRegistrar> *registrar;
544
544
@property (nonatomic , strong ) id <FVPPlayerFactory> playerFactory;
545
545
@end
546
546
547
- @implementation FLTVideoPlayerPlugin
547
+ @implementation FVPVideoPlayerPlugin
548
548
+ (void )registerWithRegistrar : (NSObject <FlutterPluginRegistrar> *)registrar {
549
- FLTVideoPlayerPlugin *instance = [[FLTVideoPlayerPlugin alloc ] initWithRegistrar: registrar];
549
+ FVPVideoPlayerPlugin *instance = [[FVPVideoPlayerPlugin alloc ] initWithRegistrar: registrar];
550
550
[registrar publish: instance];
551
- FLTAVFoundationVideoPlayerApiSetup (registrar.messenger , instance);
551
+ FVPAVFoundationVideoPlayerApiSetup (registrar.messenger , instance);
552
552
}
553
553
554
554
- (instancetype )initWithRegistrar : (NSObject <FlutterPluginRegistrar> *)registrar {
@@ -573,11 +573,11 @@ - (void)detachFromEngineForRegistrar:(NSObject<FlutterPluginRegistrar> *)registr
573
573
// TODO(57151): This should be commented out when 57151's fix lands on stable.
574
574
// This is the correct behavior we never did it in the past and the engine
575
575
// doesn't currently support it.
576
- // FLTAVFoundationVideoPlayerApiSetup (registrar.messenger, nil);
576
+ // FVPAVFoundationVideoPlayerApiSetup (registrar.messenger, nil);
577
577
}
578
578
579
- - (FLTTextureMessage *)onPlayerSetup : (FLTVideoPlayer *)player
580
- frameUpdater : (FLTFrameUpdater *)frameUpdater {
579
+ - (FVPTextureMessage *)onPlayerSetup : (FVPVideoPlayer *)player
580
+ frameUpdater : (FVPFrameUpdater *)frameUpdater {
581
581
int64_t textureId = [self .registry registerTexture: player];
582
582
frameUpdater.textureId = textureId;
583
583
FlutterEventChannel *eventChannel = [FlutterEventChannel
@@ -587,7 +587,7 @@ - (FLTTextureMessage *)onPlayerSetup:(FLTVideoPlayer *)player
587
587
[eventChannel setStreamHandler: player];
588
588
player.eventChannel = eventChannel;
589
589
self.playersByTextureId [@(textureId)] = player;
590
- FLTTextureMessage *result = [FLTTextureMessage makeWithTextureId: @(textureId)];
590
+ FVPTextureMessage *result = [FVPTextureMessage makeWithTextureId: @(textureId)];
591
591
return result;
592
592
}
593
593
@@ -596,16 +596,16 @@ - (void)initialize:(FlutterError *__autoreleasing *)error {
596
596
[[AVAudioSession sharedInstance ] setCategory: AVAudioSessionCategoryPlayback error: nil ];
597
597
598
598
[self .playersByTextureId
599
- enumerateKeysAndObjectsUsingBlock: ^(NSNumber *textureId, FLTVideoPlayer *player, BOOL *stop) {
599
+ enumerateKeysAndObjectsUsingBlock: ^(NSNumber *textureId, FVPVideoPlayer *player, BOOL *stop) {
600
600
[self .registry unregisterTexture: textureId.unsignedIntegerValue];
601
601
[player dispose ];
602
602
}];
603
603
[self .playersByTextureId removeAllObjects ];
604
604
}
605
605
606
- - (FLTTextureMessage *)create : (FLTCreateMessage *)input error : (FlutterError **)error {
607
- FLTFrameUpdater *frameUpdater = [[FLTFrameUpdater alloc ] initWithRegistry: _registry];
608
- FLTVideoPlayer *player;
606
+ - (FVPTextureMessage *)create : (FVPCreateMessage *)input error : (FlutterError **)error {
607
+ FVPFrameUpdater *frameUpdater = [[FVPFrameUpdater alloc ] initWithRegistry: _registry];
608
+ FVPVideoPlayer *player;
609
609
if (input.asset ) {
610
610
NSString *assetPath;
611
611
if (input.packageName ) {
@@ -614,7 +614,7 @@ - (FLTTextureMessage *)create:(FLTCreateMessage *)input error:(FlutterError **)e
614
614
assetPath = [_registrar lookupKeyForAsset: input.asset];
615
615
}
616
616
@try {
617
- player = [[FLTVideoPlayer alloc ] initWithAsset: assetPath
617
+ player = [[FVPVideoPlayer alloc ] initWithAsset: assetPath
618
618
frameUpdater: frameUpdater
619
619
playerFactory: _playerFactory];
620
620
return [self onPlayerSetup: player frameUpdater: frameUpdater];
@@ -623,7 +623,7 @@ - (FLTTextureMessage *)create:(FLTCreateMessage *)input error:(FlutterError **)e
623
623
return nil ;
624
624
}
625
625
} else if (input.uri ) {
626
- player = [[FLTVideoPlayer alloc ] initWithURL: [NSURL URLWithString: input.uri]
626
+ player = [[FVPVideoPlayer alloc ] initWithURL: [NSURL URLWithString: input.uri]
627
627
frameUpdater: frameUpdater
628
628
httpHeaders: input.httpHeaders
629
629
playerFactory: _playerFactory];
@@ -634,8 +634,8 @@ - (FLTTextureMessage *)create:(FLTCreateMessage *)input error:(FlutterError **)e
634
634
}
635
635
}
636
636
637
- - (void )dispose : (FLTTextureMessage *)input error : (FlutterError **)error {
638
- FLTVideoPlayer *player = self.playersByTextureId [input.textureId];
637
+ - (void )dispose : (FVPTextureMessage *)input error : (FlutterError **)error {
638
+ FVPVideoPlayer *player = self.playersByTextureId [input.textureId];
639
639
[self .registry unregisterTexture: input.textureId.intValue];
640
640
[self .playersByTextureId removeObjectForKey: input.textureId];
641
641
// If the Flutter contains https://github.com/flutter/engine/pull/12695,
@@ -656,36 +656,36 @@ - (void)dispose:(FLTTextureMessage *)input error:(FlutterError **)error {
656
656
});
657
657
}
658
658
659
- - (void )setLooping : (FLTLoopingMessage *)input error : (FlutterError **)error {
660
- FLTVideoPlayer *player = self.playersByTextureId [input.textureId];
659
+ - (void )setLooping : (FVPLoopingMessage *)input error : (FlutterError **)error {
660
+ FVPVideoPlayer *player = self.playersByTextureId [input.textureId];
661
661
player.isLooping = input.isLooping .boolValue ;
662
662
}
663
663
664
- - (void )setVolume : (FLTVolumeMessage *)input error : (FlutterError **)error {
665
- FLTVideoPlayer *player = self.playersByTextureId [input.textureId];
664
+ - (void )setVolume : (FVPVolumeMessage *)input error : (FlutterError **)error {
665
+ FVPVideoPlayer *player = self.playersByTextureId [input.textureId];
666
666
[player setVolume: input.volume.doubleValue];
667
667
}
668
668
669
- - (void )setPlaybackSpeed : (FLTPlaybackSpeedMessage *)input error : (FlutterError **)error {
670
- FLTVideoPlayer *player = self.playersByTextureId [input.textureId];
669
+ - (void )setPlaybackSpeed : (FVPPlaybackSpeedMessage *)input error : (FlutterError **)error {
670
+ FVPVideoPlayer *player = self.playersByTextureId [input.textureId];
671
671
[player setPlaybackSpeed: input.speed.doubleValue];
672
672
}
673
673
674
- - (void )play : (FLTTextureMessage *)input error : (FlutterError **)error {
675
- FLTVideoPlayer *player = self.playersByTextureId [input.textureId];
674
+ - (void )play : (FVPTextureMessage *)input error : (FlutterError **)error {
675
+ FVPVideoPlayer *player = self.playersByTextureId [input.textureId];
676
676
[player play ];
677
677
}
678
678
679
- - (FLTPositionMessage *)position : (FLTTextureMessage *)input error : (FlutterError **)error {
680
- FLTVideoPlayer *player = self.playersByTextureId [input.textureId];
681
- FLTPositionMessage *result = [FLTPositionMessage makeWithTextureId: input.textureId
679
+ - (FVPPositionMessage *)position : (FVPTextureMessage *)input error : (FlutterError **)error {
680
+ FVPVideoPlayer *player = self.playersByTextureId [input.textureId];
681
+ FVPPositionMessage *result = [FVPPositionMessage makeWithTextureId: input.textureId
682
682
position: @([player position ])];
683
683
return result;
684
684
}
685
685
686
- - (void )seekTo : (FLTPositionMessage *)input
686
+ - (void )seekTo : (FVPPositionMessage *)input
687
687
completion : (void (^)(FlutterError *_Nullable))completion {
688
- FLTVideoPlayer *player = self.playersByTextureId [input.textureId];
688
+ FVPVideoPlayer *player = self.playersByTextureId [input.textureId];
689
689
[player seekTo: input.position.intValue
690
690
completionHandler: ^(BOOL finished) {
691
691
dispatch_async (dispatch_get_main_queue (), ^{
@@ -695,12 +695,12 @@ - (void)seekTo:(FLTPositionMessage *)input
695
695
}];
696
696
}
697
697
698
- - (void )pause : (FLTTextureMessage *)input error : (FlutterError **)error {
699
- FLTVideoPlayer *player = self.playersByTextureId [input.textureId];
698
+ - (void )pause : (FVPTextureMessage *)input error : (FlutterError **)error {
699
+ FVPVideoPlayer *player = self.playersByTextureId [input.textureId];
700
700
[player pause ];
701
701
}
702
702
703
- - (void )setMixWithOthers : (FLTMixWithOthersMessage *)input
703
+ - (void )setMixWithOthers : (FVPMixWithOthersMessage *)input
704
704
error : (FlutterError *_Nullable __autoreleasing *)error {
705
705
if (input.mixWithOthers .boolValue ) {
706
706
[[AVAudioSession sharedInstance ] setCategory: AVAudioSessionCategoryPlayback
0 commit comments