     if doPause # playing -> pause
       @isPlaying = false
       @isWaitingForKeyFrame = false
-      if @stream.type is avstreams.STREAM_TYPE_RECORDED
+      if @stream?.type is avstreams.STREAM_TYPE_RECORDED
         @stream.pause?()
         logger.info "[rtmp:client=#{@clientid}] stream #{@stream.id} paused at #{msec / 1000} sec (client player time)"
 


    @lastSentTimestamp = null

    if @stream.type is avstreams.STREAM_TYPE_RECORDED
      clearQueuedRTMPMessages @stream
      _isPlaying = @isPlaying
      @isPlaying = false

      else # live stream
        callback null
    else # pausing -> resume
      if @stream?.type is avstreams.STREAM_TYPE_RECORDED
        clearQueuedRTMPMessages @stream
        # RTMP 1.0 spec says that the server only sends messages with timestamps
        # greater than the specified msec, but it appears that Flash Player expects
