     NotificationCenter.default().addObserver(forName: .NSFileHandleDataAvailable, object: nil, queue: OperationQueue.main()) { [weak self] _ in
       self?.readFromStandardInputAndWait()  
     }
+    NotificationCenter.default().addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: nil, queue: OperationQueue.main()) { [weak self] notification in
+      self?.playerItemDidFinishPlaying(notification)
+    }
     runLoop.run()
   }
+}
+
+extension EventLoop {
 
   @objc private func readFromStandardInputAndWait() {
     defer {

import Foundation

internal protocol EventHandling {
  

    let event = Event(withInput: input)
    handler?.handle(event: event)
  }

  @objc private func playerItemDidFinishPlaying(_ notification: NSNotification) {
    guard let item = notification.object as? AVPlayerItem else {
      return
    }
    handler?.handle(event: .itemFinishedPlaying(item: item))
  }
}


