     
     #if os(iOS)
     public func isAirplaying() -> Bool {
-        return player!.externalPlaybackActive
+        if player != nil {
+            return player!.externalPlaybackActive
+        }
+        
+        return false
     }
     #endif
     

        cpi = 0
        self.cpus = cpus
        playerstate.state = .ItemReady
        playerAsset = AVURLAsset.urlAssetWithURL(cpu().url, userAgent: cpu().ua) as! AVURLAsset
        playerItem = CPPlayerItem(asset: playerAsset)
        
        registerPlayerItemEvent()
        
        player = CPPlayer(playerItem: playerItem as AVPlayerItem)
        player!.actionAtItemEnd = .Pause
        #if os(iOS)
        player!.allowsExternalPlayback = allowAirPlay

    
    func deregisterPlayerItemEvent() {
        if keyobserver.status {
            playerItem!.removeObserver(self, forKeyPath:kStatusKey)
            keyobserver.status = false
        }
        
        if keyobserver.keep {
            playerItem!.removeObserver(self, forKeyPath:kPlaybackKeepUpKey)
            keyobserver.keep = false
        }
        
        if keyobserver.presentation {
            playerItem!.removeObserver(self, forKeyPath:kPresentationSizeKey)
            keyobserver.presentation = false
        }
        
        if keyobserver.duration {
            playerItem!.removeObserver(self, forKeyPath:kDurationKey)
            keyobserver.duration = false
        }
        
        if keyobserver.loaded {
            playerItem!.removeObserver(self, forKeyPath:kLoadedKey)
            keyobserver.loaded = false
        }
        
