-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
observing empty buffer to handle replay on network lost
- Loading branch information
Showing
5 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
Sources/KinescopeSDK/Player/Observers/EmptyBufferObserver.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// EmptyBufferObserver.swift | ||
// KinescopeSDK | ||
// | ||
// Created by Nikita Korobeinikov on 24.06.2024. | ||
// | ||
|
||
import Foundation | ||
import AVFoundation | ||
|
||
final class EmptyBufferObserver: KVOObserverFactory { | ||
|
||
private weak var playerBody: KinescopePlayerBody? | ||
private weak var repeater: Repeater? | ||
|
||
init(playerBody: KinescopePlayerBody, | ||
repeater: Repeater) { | ||
self.repeater = repeater | ||
self.playerBody = playerBody | ||
} | ||
|
||
func provide() -> NSKeyValueObservation? { | ||
playerBody?.strategy.player.currentItem?.observe( | ||
\.isPlaybackBufferEmpty, | ||
options: [.new, .old], | ||
changeHandler: { [weak self] item, value in | ||
let isBufferEmpty = value.newValue ?? item.isPlaybackBufferEmpty | ||
if isBufferEmpty { | ||
self?.repeater?.start() | ||
} | ||
|
||
Kinescope.shared.logger?.log( | ||
message: "AVPlayer.isPlaybackBufferEmpty – \(isBufferEmpty)", | ||
level: KinescopeLoggerLevel.player | ||
) | ||
} | ||
) | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters