Skip to content

Commit

Permalink
improving and testing new observers from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vitormesquita committed Nov 27, 2018
1 parent a265888 commit a31d1d7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
28 changes: 3 additions & 25 deletions Source/KiwiPlayer AVPlayerItemObservers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 53,8 @@ extension KiwiPlayer {
})

self.playerItemObservers.append(playerItem.observe(\.loadedTimeRanges, options: [.new, .old]) {[weak self] (item, change) in
guard let self = self else { return }

guard let self = self else { return }
self.bufferingState = .ready

// let timeRanges = item.loadedTimeRanges
// if let timeRange = timeRanges.first?.timeRangeValue {
// let bufferedTime = CMTimeGetSeconds(CMTimeAdd(timeRange.start, timeRange.duration))
// if strongSelf._lastBufferTime != bufferedTime {
// strongSelf._lastBufferTime = bufferedTime
// strongSelf.executeClosureOnMainQueueIfNecessary {
// strongSelf.playerDelegate?.playerBufferTimeDidChange(bufferedTime)
// }
// }
// }
//
// let currentTime = CMTimeGetSeconds(object.currentTime())
// let passedTime = strongSelf._lastBufferTime <= 0 ? currentTime : (strongSelf._lastBufferTime - currentTime)
//
// if (passedTime >= strongSelf.bufferSizeInSeconds ||
// strongSelf._lastBufferTime == strongSelf.maximumDuration ||
// timeRanges.first == nil) &&
// strongSelf.playbackState == .playing {
// strongSelf.play()
// }
})

self.playerItemObservers.append(playerItem.observe(\.isPlaybackBufferFull, options: [.new, .old]) {[weak self] (item, change) in
Expand Down Expand Up @@ -105,8 83,8 @@ extension KiwiPlayer {
currentItem = nextItem

currentItem?.seek(to: .zero) {[weak self] (finished) in
guard let self = self, finished else { return }
self.play()
guard let self = self else { return }
self.player.play()
}

} else {
Expand Down
3 changes: 3 additions & 0 deletions Source/KiwiPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 193,7 @@ extension KiwiPlayer {
public func setVideosURL(_ videosURL: [URL]) {
playbackState = .loading

print("KIWIPLAYER ------> START SET VIDEOS")
for url in videosURL {
let asset = AVURLAsset(url: url, options: .none)
let item = AVPlayerItem(asset: asset)
Expand All @@ -201,6 202,8 @@ extension KiwiPlayer {

setPlayerFromBeginning()
playbackState = .ready

print("KIWIPLAYER ------> END SET VIDEOS")
}

/// Set `currentPlayer` with first item in queue
Expand Down

0 comments on commit a31d1d7

Please sign in to comment.