       playerItem?.removeObserver(self, forKeyPath: "loadedTimeRanges")
       playerItem?.removeObserver(self, forKeyPath: "playbackBufferEmpty")
       playerItem?.removeObserver(self, forKeyPath: "playbackLikelyToKeepUp")
+    
+      self.playDidEnd = false
+      self.playerItem = nil
+      self.seekTime   = 0
+      
+      self.timer?.invalidate()
+      
+      self.pause()
+      // 移除原来的layer
+      self.playerLayer?.removeFromSuperlayer()
+      // 替换PlayerItem为nil
+      self.player?.replaceCurrentItem(with: nil)
       player?.removeObserver(self, forKeyPath: "rate")
-    
-      self.playDidEnd = false
-        self.playerItem = nil
-        self.seekTime   = 0
-        
-        self.timer?.invalidate()
-        
-        self.pause()
-        // 移除原来的layer
-        self.playerLayer?.removeFromSuperlayer()
-        // 替换PlayerItem为nil
-        self.player?.replaceCurrentItem(with: nil)
-        player?.removeObserver(self, forKeyPath: "rate")
-        
-        // 把player置为nil
-        self.player = nil
+      
+      // 把player置为nil
+      self.player = nil
     }
     
     open func prepareToDeinit() {

                    if let timeInterVarl    = self.availableDuration() {
                        let duration        = item.duration
                        let totalDuration   = CMTimeGetSeconds(duration)
                        delegate?.bmPlayer(player: self, loadedTimeDidChange: timeInterVarl, totalDuration: totalDuration)
                    }
                    
                case "playbackBufferEmpty":

        playerItem = AVPlayerItem(asset: urlAsset!)
        player     = AVPlayer(playerItem: playerItem!)
        player!.addObserver(self, forKeyPath: "rate", options: NSKeyValueObservingOptions.new, context: nil)
        playerLayer?.removeFromSuperlayer()
        playerLayer = AVPlayerLayer(player: player)
        playerLayer!.videoGravity = videoGravity
        layer.addSublayer(playerLayer!)
        setNeedsLayout()
        layoutIfNeeded()
    }
