     if let audioPath = getMediaUrl(path: path) {
       let asset = AVAsset(url: audioPath)
       let playerItem = AVPlayerItem(asset: asset)
+
+      if currentItem != nil {
+        defaultNotificationCenter.removeObserver(self, name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: playerItem)
+      }
+
+      defaultNotificationCenter.addObserver(self, selector: #selector(self.playerItemDidPlayToEnd(_:)),
+        name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: playerItem)
 
       player = AVPlayer(playerItem: playerItem)
     }

    }
    else {
      replay()
    }
  }


          play()
      }
    }
    else {
      play()
    }
  }

  func pause() {
