     case playPrevious
     case toggleShuffle
     case jumpToItem(index: Int)
+    case itemFinishedPlaying(item: AVPlayerItem)
 
     private static let inputMap: [String : Event] = [
       "s"        : .start,

import Foundation

internal protocol EventHandling {
  

    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 {
