Skip to content

Commit

Permalink
Move playerItemDidPlayToEndTime to source object
Browse files Browse the repository at this point in the history
  • Loading branch information
pm-dev committed Jan 19, 2021
1 parent 7c5c298 commit aeb8ba7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
14 changes: 1 addition & 13 deletions MediaSlideshow/Source/AV/AVPlayerSlide.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,11 @@ public class AVPlayerSlide: AVPlayerView, MediaSlideshowSlide {
playerTimeControlStatusObservation = source.player.observe(\.timeControlStatus) { [weak self] player, _ in
self?.overlayView?.playerDidUpdateStatus(player.timeControlStatus)
}
NotificationCenter.default.addObserver(
self,
selector: #selector(playerItemDidPlayToEndTime(notification:)),
name: .AVPlayerItemDidPlayToEndTime,
object: source.item)
}

required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

@objc
private func playerItemDidPlayToEndTime(notification: Notification) {
source.player.seek(to: .zero)
}

private func setPlayerViewVideoGravity() {
switch mediaContentMode {
Expand All @@ -88,9 +78,7 @@ public class AVPlayerSlide: AVPlayerView, MediaSlideshowSlide {

public func willBeRemoved() {}

public func loadMedia() {
_ = source.player
}
public func loadMedia() {}

public func releaseMedia() {}

Expand Down
12 changes: 11 additions & 1 deletion MediaSlideshow/Source/AV/AVSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,26 @@ open class AVSource: NSObject, MediaSource {
self.asset = asset
self.onAppear = onAppear
super.init()
NotificationCenter.default.addObserver(
self,
selector: #selector(playerItemDidPlayToEndTime(notification:)),
name: .AVPlayerItemDidPlayToEndTime,
object: item)
}

public convenience init(url: URL, onAppear: Playback) {
self.init(asset: AVAsset(url: url), onAppear: onAppear)
}

public func slide(in slideshow: MediaSlideshow) -> MediaSlideshowSlide {
open func slide(in slideshow: MediaSlideshow) -> MediaSlideshowSlide {
AVPlayerSlide(
source: self,
overlayView: StandardAVSlideOverlayView(activityView: slideshow.activityIndicator?.create()),
mediaContentMode: slideshow.contentScaleMode)
}

@objc
open func playerItemDidPlayToEndTime(notification: Notification) {
player.seek(to: .zero)
}
}

0 comments on commit aeb8ba7

Please sign in to comment.