@@ -224,7 +224,7 @@ private extension CLPlayerView {
224
224
currentDuration = totalDuration
225
225
playbackProgress = 1.0
226
226
contentView. playState = . ended
227
- sliderTimer? . suspend ( )
227
+ sliderTimer? . pause ( )
228
228
DispatchQueue . main. async {
229
229
self . playToEndHandler ? ( )
230
230
}
@@ -269,7 +269,7 @@ private extension CLPlayerView {
269
269
totalDuration = TimeInterval ( playerItem. duration. value) / TimeInterval( playerItem. duration. timescale)
270
270
271
271
sliderTimer = CLGCDTimer ( interval: 0.1 )
272
- sliderTimer? . start { [ weak self] _ in
272
+ sliderTimer? . run { [ weak self] _ in
273
273
self ? . sliderTimerAction ( )
274
274
}
275
275
@@ -323,13 +323,13 @@ private extension CLPlayerView {
323
323
guard contentView. playState != . failed else { return }
324
324
325
325
player? . pause ( )
326
- sliderTimer? . suspend ( )
327
- bufferTimer = nil
326
+ sliderTimer? . pause ( )
328
327
329
328
contentView. playState = . buffering
330
- bufferTimer = CLGCDTimer ( interval: 0 , delaySecs : 3.0 )
331
- bufferTimer? . start { [ weak self] _ in
329
+ bufferTimer = CLGCDTimer ( interval: 3. 0, initialDelay : 3.0 )
330
+ bufferTimer? . run { [ weak self] _ in
332
331
guard let playerItem = self ? . playerItem else { return }
332
+ self ? . bufferTimer = nil
333
333
if playerItem. isPlaybackLikelyToKeepUp {
334
334
self ? . play ( )
335
335
} else {
@@ -351,17 +351,19 @@ private extension CLPlayerView {
351
351
352
352
private extension CLPlayerView {
353
353
func dismiss( ) {
354
+ guard Thread . isMainThread else { return DispatchQueue . main. async { self . dismiss ( ) } }
354
355
guard contentView. screenState == . fullScreen else { return }
355
356
guard let controller = fullScreenController else { return }
356
357
contentView. screenState = . animating
357
358
controller. dismiss ( animated: true , completion: {
358
359
self . contentView. screenState = . small
360
+ self . fullScreenController = nil
361
+ UIViewController . attemptRotationToDeviceOrientation ( )
359
362
} )
360
- fullScreenController = nil
361
- UIViewController . attemptRotationToDeviceOrientation ( )
362
363
}
363
364
364
365
func presentWithOrientation( _ orientation: CLAnimationTransitioning . CLAnimationOrientation ) {
366
+ guard Thread . isMainThread else { return DispatchQueue . main. async { self . presentWithOrientation ( orientation) } }
365
367
guard superview != nil else { return }
366
368
guard fullScreenController == nil else { return }
367
369
guard contentView. screenState == . small else { return }
@@ -404,6 +406,7 @@ extension CLPlayerView {
404
406
player? . rate = rate
405
407
sliderTimer? . resume ( )
406
408
waitReadyToPlayState = . nomal
409
+ bufferTimer = nil
407
410
}
408
411
409
412
func pause( ) {
@@ -413,7 +416,7 @@ extension CLPlayerView {
413
416
}
414
417
contentView. playState = . pause
415
418
player? . pause ( )
416
- sliderTimer? . suspend ( )
419
+ sliderTimer? . pause ( )
417
420
bufferTimer = nil
418
421
waitReadyToPlayState = . nomal
419
422
}
0 commit comments