Skip to content

Commit bcf1c4c

Browse files
committed
NSTimer scheduledTimerWithTimeInterval API AVAILABLE from macOS 10.12
1 parent 533b2d7 commit bcf1c4c

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

ijkmedia/wrapper/apple/FSOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ NS_ASSUME_NONNULL_BEGIN
6969
//setup audio session use AVAudioSessionCategoryPlayback ,observer and handle interrupt event
7070
@property(nonatomic) BOOL automaticallySetupAudioSession;
7171
//default is 0, when the value is 0, it is not turned on.
72-
@property(nonatomic) NSTimeInterval currentPlaybackTimeNotificationInterval;
72+
@property(nonatomic) NSTimeInterval currentPlaybackTimeNotificationInterval API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0));
7373

7474
@end
7575
NS_ASSUME_NONNULL_END

ijkmedia/wrapper/apple/FSOptions.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ + (FSOptions *)optionsByDefault
5151
options.showHudView = NO;
5252
options.metalRenderer = YES;
5353
options.automaticallySetupAudioSession = YES;
54-
options.currentPlaybackTimeNotificationInterval = 0;
54+
if (@available(macOS 10.12, *)) {
55+
options.currentPlaybackTimeNotificationInterval = 0;
56+
} else {
57+
// Fallback on earlier versions
58+
}
5559
return options;
5660
}
5761

ijkmedia/wrapper/apple/FSPlayer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ NS_ASSUME_NONNULL_BEGIN
137137

138138
@property(nonatomic, readonly) CGFloat fpsInMeta;
139139
@property(nonatomic, readonly) CGFloat fpsAtOutput;
140-
@property(nonatomic) BOOL shouldShowHudView;
140+
@property(nonatomic) BOOL shouldShowHudView API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0));
141141
//when sampleSize is -1,the samples is NULL,means needs reset and refresh ui.
142142
@property(nonatomic, copy) void (^audioSamplesCallback)(int16_t * _Nullable samples, int sampleSize, int sampleRate, int channels);
143143

144-
- (NSDictionary *)allHudItem;
144+
- (NSDictionary *)allHudItem API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0));
145145

146146
- (void)setOptionValue:(NSString *)value
147147
forKey:(NSString *)key

ijkmedia/wrapper/apple/FSPlayer.m

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ @implementation FSPlayer {
8686
int _enableAccurateSeek;
8787
BOOL _canUpdateAccurateSeek;
8888

89-
NSTimer *_playbackTimeNotifiTimer;
89+
__weak NSTimer *_playbackTimeNotifiTimer;
9090
NSTimeInterval _playbackTimeNotifiInterval;
9191
}
9292

@@ -207,7 +207,11 @@ - (void)_initWithContent:(NSURL *)aUrl
207207
_scalingMode = FSScalingModeAspectFit;
208208
_shouldAutoplay = YES;
209209
_canUpdateAccurateSeek = YES;
210-
_playbackTimeNotifiInterval = options.currentPlaybackTimeNotificationInterval;
210+
if (@available(macOS 10.12, *)) {
211+
_playbackTimeNotifiInterval = options.currentPlaybackTimeNotificationInterval;
212+
} else {
213+
// Fallback on earlier versions
214+
}
211215

212216
memset(&_asyncStat, 0, sizeof(_asyncStat));
213217
memset(&_cacheStat, 0, sizeof(_cacheStat));
@@ -241,7 +245,11 @@ - (void)_initWithContent:(NSURL *)aUrl
241245
// init hud
242246
_hudCtrl = [FSSDLHudControl new];
243247

244-
self.shouldShowHudView = options.showHudView;
248+
if (@available(macOS 10.12, *)) {
249+
self.shouldShowHudView = options.showHudView;
250+
} else {
251+
// Fallback on earlier versions
252+
}
245253
} else {
246254
[options setPlayerOptionIntValue:1 forKey:@"display_disable"];
247255
[options setPlayerOptionIntValue:0 forKey:@"subtitle_mix"];
@@ -471,7 +479,11 @@ - (void)play
471479

472480
[self setScreenOn:_keepScreenOnWhilePlaying];
473481

474-
[self startHudTimer];
482+
if (@available(macOS 10.12, *)) {
483+
[self startHudTimer];
484+
} else {
485+
// Fallback on earlier versions
486+
}
475487
ijkmp_start(_mediaPlayer);
476488
}
477489

@@ -1074,7 +1086,7 @@ - (void)refreshHudView
10741086
forKey:@"tcp-spd"];
10751087
}
10761088

1077-
- (void)startHudTimer
1089+
- (void)startHudTimer API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0))
10781090
{
10791091
if (!_shouldShowHudView)
10801092
return;
@@ -1493,8 +1505,13 @@ - (void)postEvent: (FSPlayerMessage *)msg
14931505
ijkmp_set_playback_rate(_mediaPlayer, [self playbackRate]);
14941506
ijkmp_set_playback_volume(_mediaPlayer, [self playbackVolume]);
14951507

1496-
[self startHudTimer];
1497-
[self createPlaybackTimeNotifiTimerIfNeed];
1508+
if (@available(macOS 10.12, *)) {
1509+
[self startHudTimer];
1510+
[self createPlaybackTimeNotifiTimerIfNeed];
1511+
} else {
1512+
// Fallback on earlier versions
1513+
}
1514+
14981515
_isPreparedToPlay = YES;
14991516

15001517
[[NSNotificationCenter defaultCenter] postNotificationName:FSPlayerIsPreparedToPlayNotification object:self];
@@ -1795,7 +1812,7 @@ - (void)setHudUrl:(NSURL *)url
17951812
}
17961813
}
17971814

1798-
- (void)createPlaybackTimeNotifiTimerIfNeed {
1815+
- (void)createPlaybackTimeNotifiTimerIfNeed API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0)) {
17991816
if (!_playbackTimeNotifiTimer && _playbackTimeNotifiInterval > 0) {
18001817
__weak __typeof(self) weakSelf = self;
18011818
_playbackTimeNotifiTimer = [NSTimer scheduledTimerWithTimeInterval:_playbackTimeNotifiInterval repeats:YES block:^(NSTimer *timer) {
@@ -1805,7 +1822,7 @@ - (void)createPlaybackTimeNotifiTimerIfNeed {
18051822
}
18061823
}
18071824

1808-
- (void)onPlaybackTimeTick {
1825+
- (void)onPlaybackTimeTick API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0)) {
18091826
if (!_mediaPlayer || !self.isPlaying) {
18101827
return;
18111828
}

0 commit comments

Comments
 (0)